Reputation: 3991
I'm developing a real-time web app. The back end is NodeJS and ArangoDB. I would like to generate and send a unique _key to the web app in advance of creation of a document. That way the document can be created quickly on the fly without having to wait for a response from the server with the newly generated ID. To clarify:
This is just a rough overview of the intended workflow. I believe CouchDB has a function that will provide a user with unique ID's: http://docs.couchdb.org/en/1.6.1/api/server/common.html?highlight=id#get--_uuids
I did find this code in the ArangoDB documentation:
FOR i IN 1..10
INSERT { value: i } IN test
RETURN { _key: NEW._key, value: i }
It creates a batch of unique keys in a collection. However, I was unsure if the keys generated here would be unique for ALL collections or, what seems more likely, just the collection they are generated for. My app needs a key that could be used for any collection.
Is there a way to fetch one or more unique keys that could be used on multiple collections from ArangoDB? Is there a different way to approach this issue?
Upvotes: 2
Views: 1823
Reputation: 10892
Keys are always relative to the collection. The full document _id
always consists of the collection name and the document key.
If you want to define keys yourself, you can simply provide a _key
property as part of the document when saving it to the w collection. Of course this means it becomes your application's responsibility to pick unique keys and resolve any conflicts (i.e. failed saves due to duplicate keys). UUIDs are a good option if you don't mind the format.
Upvotes: 7