ArangoDB key value to store Google certificates

507 Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER

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/3.11/develop/javascript-api/@arangodb/db-object/#db_createcollection-name--properties--type--options

0
On

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