Bulk Document Lookups: Efficient Data Retrieval with ArangoDB
ArangoDB 2.6 comes with a specialized API for bulk document lookups. The new API allows fetching multiple documents from the server using a single request, making bulk document retrieval more efficient than when using one request per document to fetch.
Provided the documents keys are known, all the client application needs to do is to call the collection’s lookupByKeys
method:
// list of document keys
var keys = [ "foo", "bar", "baz", ...];
var results = db.test.lookupByKeys(keys);
// now all documents are contained in variable 'results'
Additionally, the server-side REST API method for bulk document lookups can be invoked directly via HTTP as follows:
curl \
-X PUT \
http://127.0.0.1:8529/_api/simple/lookup-by-keys \
--data '{"collection":"test","keys":["foo","bar","baz"]}'
Jan compared the functionality with single document requests in his latest blog post.
3 Comments
Leave a Comment
Get the latest tutorials, blog posts and news:
Have you considered the following API?
db.test.documents(…)
http://server:port/_api/documents
Seems more in line with https://docs.arangodb.com/Documents/DocumentMethods.html#document
Thanks for the suggestion. db.test.documents(…) makes perfect sense. I need to check whether the HTTP endpoint URL can also be changed easily.
I spotted a difference between document(…) and a possible documents(…) reading your blog post: the latter would accept document keys only, the other keys as well as ids.
Perhaps documents(…) could be improved to ignore the collection-part of ids and use the document key only, to keep both as similar as possible? (ids from collections other than the one specified in the bulk request should be completely ignored I guess)