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:
- User logs in and Web app receives unique key from ArangoDB (via NodeJS)
- User creates a new document and Web App assigns it the unique key it was given in step 1
- Web app immediately requests a new unique key for use now that the previous one is being used
- User saves the newly created document to one of many collections in the database using the unique key from step 1
- Web app updates it's local cache of documents without needing to wait for auto generated key from database
- Begin again at step 2
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?