1

how do I use promised key value storage in ArangoDB? I want to store Google Certificates in ArangoDB in most effective way or better - most convenient way, which would be associative array resp. key-value. But i can not find anything about it in database.

Solutions I came up with are to make one document which would be wtorage for all keys and I'd acces it like db.Certificates.document('certificates')[hash] and second is to store documents like db.Certificates.insert({'_key': hash, 'value': '.... google certificate ....'}) which would I access as db.Certificates.document(hash).value

I don't like those solutions since they don't seem right, values are one level deeper as I'd expect from key-value storage. Or is there any faster way to store certificates? Maybe somehow in RAM instead of db storage? I need them to be accessible across all callings of my foxx application and change them when they expire. Thanks.

CodeManX
  • 11,159
  • 5
  • 49
  • 70
Márius Rak
  • 1,356
  • 2
  • 15
  • 35

2 Answers2

2

If you don't need the data to be persistent, you can use a volatile collection instead. Volatile collections will never be synced to disk so documents (but not the collection itself) will be lost between restarts -- but they are quite a bit faster because the data only lives in RAM.

You can create a volatile collection like a regular collection by passing the isVolatile option:

var db = require('org/arangodb').db;
var volatileCollection = db._create('temp', {isVolatile: true});

You can find more information in the chapter on creating collections: https://docs.arangodb.com/Collections/DatabaseMethods.html#create

Alan Plum
  • 10,814
  • 4
  • 40
  • 57
1

No, Collections are absolutely the way to go.

You would parse the json using JSON.parse(), then iterate and save them like this

db.certificates.save({_key: hashkey, value: certificate})

and later on fetch it using AQL:

FOR cert IN certificates FILTER _key == '<hashkey>' RETURN cert
dothebart
  • 5,972
  • 16
  • 40