Collection Methods

All

collection.all()

Fetches all documents from a collection and returns a cursor. You can use toArray, next, or hasNext to access the result. The result can be limited using the skip and limit operator.

Examples

Use toArray to get all documents at once:

  1. arangosh> db.five.insert({ name : "one" });
  2. arangosh> db.five.insert({ name : "two" });
  3. arangosh> db.five.insert({ name : "three" });
  4. arangosh> db.five.insert({ name : "four" });
  5. arangosh> db.five.insert({ name : "five" });
  6. arangosh> db.five.all().toArray();

Show execution results

Hide execution results

  1. {
  2. "_id" : "five/117",
  3. "_key" : "117",
  4. "_rev" : "_dAzO9si---"
  5. }
  6. {
  7. "_id" : "five/119",
  8. "_key" : "119",
  9. "_rev" : "_dAzO9sm---"
  10. }
  11. {
  12. "_id" : "five/121",
  13. "_key" : "121",
  14. "_rev" : "_dAzO9sm--A"
  15. }
  16. {
  17. "_id" : "five/123",
  18. "_key" : "123",
  19. "_rev" : "_dAzO9sq---"
  20. }
  21. {
  22. "_id" : "five/125",
  23. "_key" : "125",
  24. "_rev" : "_dAzO9sq--A"
  25. }
  26. [
  27. {
  28. "_key" : "117",
  29. "_id" : "five/117",
  30. "_rev" : "_dAzO9si---",
  31. "name" : "one"
  32. },
  33. {
  34. "_key" : "119",
  35. "_id" : "five/119",
  36. "_rev" : "_dAzO9sm---",
  37. "name" : "two"
  38. },
  39. {
  40. "_key" : "121",
  41. "_id" : "five/121",
  42. "_rev" : "_dAzO9sm--A",
  43. "name" : "three"
  44. },
  45. {
  46. "_key" : "123",
  47. "_id" : "five/123",
  48. "_rev" : "_dAzO9sq---",
  49. "name" : "four"
  50. },
  51. {
  52. "_key" : "125",
  53. "_id" : "five/125",
  54. "_rev" : "_dAzO9sq--A",
  55. "name" : "five"
  56. }
  57. ]

Use limit to restrict the documents:

  1. arangosh> db.five.insert({ name : "one" });
  2. arangosh> db.five.insert({ name : "two" });
  3. arangosh> db.five.insert({ name : "three" });
  4. arangosh> db.five.insert({ name : "four" });
  5. arangosh> db.five.insert({ name : "five" });
  6. arangosh> db.five.all().limit(2).toArray();

Show execution results

Hide execution results

  1. {
  2. "_id" : "five/137",
  3. "_key" : "137",
  4. "_rev" : "_dAzO9t6---"
  5. }
  6. {
  7. "_id" : "five/139",
  8. "_key" : "139",
  9. "_rev" : "_dAzO9t6--A"
  10. }
  11. {
  12. "_id" : "five/141",
  13. "_key" : "141",
  14. "_rev" : "_dAzO9u----"
  15. }
  16. {
  17. "_id" : "five/143",
  18. "_key" : "143",
  19. "_rev" : "_dAzO9u---A"
  20. }
  21. {
  22. "_id" : "five/145",
  23. "_key" : "145",
  24. "_rev" : "_dAzO9uC---"
  25. }
  26. [
  27. {
  28. "_key" : "137",
  29. "_id" : "five/137",
  30. "_rev" : "_dAzO9t6---",
  31. "name" : "one"
  32. },
  33. {
  34. "_key" : "139",
  35. "_id" : "five/139",
  36. "_rev" : "_dAzO9t6--A",
  37. "name" : "two"
  38. }
  39. ]

Query by example

collection.byExample(example)

Fetches all documents from a collection that match the specified example and returns a cursor.

You can use toArray, next, or hasNext to access the result. The result can be limited using the skip and limit operator.

An attribute name of the form a.b is interpreted as attribute path, not as attribute. If you use

  1. { "a" : { "c" : 1 } }

as example, then you will find all documents, such that the attribute a contains a document of the form {c : 1 }. For example the document

  1. { "a" : { "c" : 1 }, "b" : 1 }

will match, but the document

  1. { "a" : { "c" : 1, "b" : 1 } }

will not.

However, if you use

  1. { "a.c" : 1 }

then you will find all documents, which contain a sub-document in a that has an attribute c of value 1. Both the following documents

  1. { "a" : { "c" : 1 }, "b" : 1 }

and

  1. { "a" : { "c" : 1, "b" : 1 } }

will match.

  1. collection.byExample(path1, value1, ...)

As alternative you can supply an array of paths and values.

Examples

Use toArray to get all documents at once:

  1. arangosh> db.users.insert({ name: "Gerhard" });
  2. arangosh> db.users.insert({ name: "Helmut" });
  3. arangosh> db.users.insert({ name: "Angela" });
  4. arangosh> db.users.all().toArray();
  5. arangosh> db.users.byExample({ "_id" : "users/20" }).toArray();
  6. arangosh> db.users.byExample({ "name" : "Gerhard" }).toArray();
  7. arangosh> db.users.byExample({ "name" : "Helmut", "_id" : "users/15" }).toArray();

Show execution results

Hide execution results

  1. {
  2. "_id" : "users/157",
  3. "_key" : "157",
  4. "_rev" : "_dAzO9ua--A"
  5. }
  6. {
  7. "_id" : "users/159",
  8. "_key" : "159",
  9. "_rev" : "_dAzO9ue---"
  10. }
  11. {
  12. "_id" : "users/161",
  13. "_key" : "161",
  14. "_rev" : "_dAzO9ue--A"
  15. }
  16. [
  17. {
  18. "_key" : "157",
  19. "_id" : "users/157",
  20. "_rev" : "_dAzO9ua--A",
  21. "name" : "Gerhard"
  22. },
  23. {
  24. "_key" : "159",
  25. "_id" : "users/159",
  26. "_rev" : "_dAzO9ue---",
  27. "name" : "Helmut"
  28. },
  29. {
  30. "_key" : "161",
  31. "_id" : "users/161",
  32. "_rev" : "_dAzO9ue--A",
  33. "name" : "Angela"
  34. }
  35. ]
  36. [ ]
  37. [
  38. {
  39. "_key" : "157",
  40. "_id" : "users/157",
  41. "_rev" : "_dAzO9ua--A",
  42. "name" : "Gerhard"
  43. }
  44. ]
  45. [ ]

Use next to loop over all documents:

  1. arangosh> db.users.insert({ name: "Gerhard" });
  2. arangosh> db.users.insert({ name: "Helmut" });
  3. arangosh> db.users.insert({ name: "Angela" });
  4. arangosh> var a = db.users.byExample( {"name" : "Angela" } );
  5. arangosh> while (a.hasNext()) print(a.next());

Show execution results

Hide execution results

  1. {
  2. "_id" : "users/179",
  3. "_key" : "179",
  4. "_rev" : "_dAzO9vC---"
  5. }
  6. {
  7. "_id" : "users/181",
  8. "_key" : "181",
  9. "_rev" : "_dAzO9vC--A"
  10. }
  11. {
  12. "_id" : "users/183",
  13. "_key" : "183",
  14. "_rev" : "_dAzO9vG---"
  15. }
  16. {
  17. "_key" : "183",
  18. "_id" : "users/183",
  19. "_rev" : "_dAzO9vG---",
  20. "name" : "Angela"
  21. }

First Example

collection.firstExample(example)

Returns some document of a collection that matches the specified example. If no such document exists, null will be returned. The example has to be specified as paths and values. See byExample for details.

collection.firstExample(path1, value1, ...)

As alternative you can supply an array of paths and values.

Examples

  1. arangosh> db.users.firstExample("name", "Angela");

Show execution results

Hide execution results

  1. {
  2. "_key" : "75628",
  3. "_id" : "users/75628",
  4. "_rev" : "_dAzP03W---",
  5. "name" : "Angela"
  6. }

Range

collection.range(attribute, left, right)

Returns all documents from a collection such that the attribute is greater or equal than left and strictly less than right.

You can use toArray, next, or hasNext to access the result. The result can be limited using the skip and limit operator.

An attribute name of the form a.b is interpreted as attribute path, not as attribute.

Note: the range simple query function is deprecated as of ArangoDB 2.6. The function may be removed in future versions of ArangoDB. The preferred way for retrieving documents from a collection within a specific range is to use an AQL query as follows:

  1. FOR doc IN @@collection
  2. FILTER doc.value >= @left && doc.value < @right
  3. LIMIT @skip, @limit
  4. RETURN doc

Examples

Use toArray to get all documents at once:

  1. arangosh> db.old.ensureIndex({ type: "skiplist", fields: [ "age" ] });
  2. arangosh> db.old.insert({ age: 15 });
  3. arangosh> db.old.insert({ age: 25 });
  4. arangosh> db.old.insert({ age: 30 });
  5. arangosh> db.old.range("age", 10, 30).toArray();

Show execution results

Hide execution results

  1. {
  2. "deduplicate" : true,
  3. "fields" : [
  4. "age"
  5. ],
  6. "id" : "old/194",
  7. "isNewlyCreated" : true,
  8. "name" : "idx_1712165072807133184",
  9. "selectivityEstimate" : 1,
  10. "sparse" : false,
  11. "type" : "skiplist",
  12. "unique" : false,
  13. "code" : 201
  14. }
  15. {
  16. "_id" : "old/198",
  17. "_key" : "198",
  18. "_rev" : "_dAzO9vi---"
  19. }
  20. {
  21. "_id" : "old/200",
  22. "_key" : "200",
  23. "_rev" : "_dAzO9vm---"
  24. }
  25. {
  26. "_id" : "old/202",
  27. "_key" : "202",
  28. "_rev" : "_dAzO9vm--A"
  29. }
  30. [
  31. {
  32. "_key" : "198",
  33. "_id" : "old/198",
  34. "_rev" : "_dAzO9vi---",
  35. "age" : 15
  36. },
  37. {
  38. "_key" : "200",
  39. "_id" : "old/200",
  40. "_rev" : "_dAzO9vm---",
  41. "age" : 25
  42. }
  43. ]

Closed range

collection.closedRange(attribute, left, right)

Returns all documents of a collection such that the attribute is greater or equal than left and less or equal than right.

You can use toArray, next, or hasNext to access the result. The result can be limited using the skip and limit operator.

An attribute name of the form a.b is interpreted as attribute path, not as attribute.

Note: the closedRange simple query function is deprecated as of ArangoDB 2.6. The function may be removed in future versions of ArangoDB. The preferred way for retrieving documents from a collection within a specific range is to use an AQL query as follows:

  1. FOR doc IN @@collection
  2. FILTER doc.value >= @left && doc.value <= @right
  3. LIMIT @skip, @limit
  4. RETURN doc

Examples

Use toArray to get all documents at once:

  1. arangosh> db.old.ensureIndex({ type: "skiplist", fields: [ "age" ] });
  2. arangosh> db.old.insert({ age: 15 });
  3. arangosh> db.old.insert({ age: 25 });
  4. arangosh> db.old.insert({ age: 30 });
  5. arangosh> db.old.closedRange("age", 10, 30).toArray();

Show execution results

Hide execution results

  1. {
  2. "deduplicate" : true,
  3. "fields" : [
  4. "age"
  5. ],
  6. "id" : "old/214",
  7. "isNewlyCreated" : true,
  8. "name" : "idx_1712165072817618946",
  9. "selectivityEstimate" : 1,
  10. "sparse" : false,
  11. "type" : "skiplist",
  12. "unique" : false,
  13. "code" : 201
  14. }
  15. {
  16. "_id" : "old/218",
  17. "_key" : "218",
  18. "_rev" : "_dAzO9wK---"
  19. }
  20. {
  21. "_id" : "old/220",
  22. "_key" : "220",
  23. "_rev" : "_dAzO9wO---"
  24. }
  25. {
  26. "_id" : "old/222",
  27. "_key" : "222",
  28. "_rev" : "_dAzO9wO--A"
  29. }
  30. [
  31. {
  32. "_key" : "218",
  33. "_id" : "old/218",
  34. "_rev" : "_dAzO9wK---",
  35. "age" : 15
  36. },
  37. {
  38. "_key" : "220",
  39. "_id" : "old/220",
  40. "_rev" : "_dAzO9wO---",
  41. "age" : 25
  42. },
  43. {
  44. "_key" : "222",
  45. "_id" : "old/222",
  46. "_rev" : "_dAzO9wO--A",
  47. "age" : 30
  48. }
  49. ]

Any

collection.any()

Returns a random document from the collection or null if none exists.

Note: this method is expensive when using the RocksDB storage engine.

Count

collection.count()

Returns the number of living documents in the collection.

Examples

  1. arangosh> db.users.count();

Show execution results

Hide execution results

  1. 0

toArray

collection.toArray()

Converts the collection into an array of documents. Never use this call in a production environment as it will basically create a copy of your collection in RAM which will use resources depending on the number and size of the documents in your collecion.

Document

collection.document(object)

The document method finds a document given an object object containing the _id or _key attribute. The method returns the document if it can be found. If both attributes are given, the _id takes precedence, it is an error, if the collection part of the _id does not match the collection.

An error is thrown if _rev is specified but the document found has a different revision already. An error is also thrown if no document exists with the given _id or _key value.

Please note that if the method is executed on the arangod server (e.g. from inside a Foxx application), an immutable document object will be returned for performance reasons. It is not possible to change attributes of this immutable object. To update or patch the returned document, it needs to be cloned/copied into a regular JavaScript object first. This is not necessary if the document method is called from out of arangosh or from any other client.

collection.document(document-handle)

As before. Instead of object a document-handle can be passed as first argument. No revision can be specified in this case.

collection.document(document-key)

As before. Instead of object a document-key can be passed as first argument.

collection.document(array)

This variant allows to perform the operation on a whole array of arguments. The behavior is exactly as if document would have been called on all members of the array separately and all results are returned in an array. If an error occurs with any of the documents, no exception is risen! Instead of a document an error object is returned in the result array.

Examples

Returns the document for a document-handle:

  1. arangosh> db.example.document("example/2873916");

Show execution results

Hide execution results

  1. {
  2. "_key" : "2873916",
  3. "_id" : "example/2873916",
  4. "_rev" : "_dAzP1Cm--A"
  5. }

Returns the document for a document-key:

  1. arangosh> db.example.document("2873916");

Show execution results

Hide execution results

  1. {
  2. "_key" : "2873916",
  3. "_id" : "example/2873916",
  4. "_rev" : "_dAzP1B2---"
  5. }

Returns the document for an object:

  1. arangosh> db.example.document({_id: "example/2873916"});

Show execution results

Hide execution results

  1. {
  2. "_key" : "2873916",
  3. "_id" : "example/2873916",
  4. "_rev" : "_dAzP1CG---"
  5. }

Returns the document for an array of two keys:

  1. arangosh> db.example.document(["2873916","2873917"]);

Show execution results

Hide execution results

  1. [
  2. {
  3. "_key" : "2873916",
  4. "_id" : "example/2873916",
  5. "_rev" : "_dAzP1CW---"
  6. },
  7. {
  8. "_key" : "2873917",
  9. "_id" : "example/2873917",
  10. "_rev" : "_dAzP1Ca---"
  11. }
  12. ]

An error is raised if the document is unknown:

  1. arangosh> db.example.document("example/4472917");

Show execution results

Hide execution results

  1. [ArangoError 1202: document not found]

An error is raised if the handle is invalid:

  1. arangosh> db.example.document("");

Show execution results

Hide execution results

  1. [ArangoError 1205: illegal document identifier]

Changes in 3.0 from 2.8:

document can now query multiple documents with one call.

Exists

checks whether a document exists collection.exists(object)

The exists method determines whether a document exists given an object object containing the _id or _key attribute. If both attributes are given, the _id takes precedence, it is an error, if the collection part of the _id does not match the collection.

An error is thrown if _rev is specified but the document found has a different revision already.

Instead of returning the found document or an error, this method will only return an object with the attributes _id, _key and _rev, or false if no document with the given _id or _key exists. It can thus be used for easy existence checks.

This method will throw an error if used improperly, e.g. when called with a non-document handle, a non-document, or when a cross-collection request is performed.

collection.exists(document-handle)

As before. Instead of object a document-handle can be passed as first argument.

collection.exists(document-key)

As before. Instead of object a document-key can be passed as first argument.

collection.exists(array)

This variant allows to perform the operation on a whole array of arguments. The behavior is exactly as if exists would have been called on all members of the array separately and all results are returned in an array. If an error occurs with any of the documents, the operation stops immediately returning only an error object.

Changes in 3.0 from 2.8:

In the case of a revision mismatch exists now throws an error instead of simply returning false. This is to make it possible to tell the difference between a revision mismatch and a non-existing document.

exists can now query multiple documents with one call.

Lookup By Keys

collection.documents(keys)

Looks up the documents in the specified collection using the array of keys provided. All documents for which a matching key was specified in the keys array and that exist in the collection will be returned. Keys for which no document can be found in the underlying collection are ignored, and no exception will be thrown for them.

This method is deprecated in favour of the array variant of document.

Examples

  1. arangosh> keys = [ ];
  2. arangosh> for (var i = 0; i < 10; ++i) {
  3. ........> db.example.insert({ _key: "test" + i, value: i });
  4. ........> keys.push("test" + i);
  5. ........> }
  6. arangosh> db.example.documents(keys);

Show execution results

Hide execution results

  1. [ ]
  2. {
  3. "documents" : [
  4. {
  5. "_key" : "test0",
  6. "_id" : "example/test0",
  7. "_rev" : "_dAzP04y--A",
  8. "value" : 0
  9. },
  10. {
  11. "_key" : "test1",
  12. "_id" : "example/test1",
  13. "_rev" : "_dAzP042---",
  14. "value" : 1
  15. },
  16. {
  17. "_key" : "test2",
  18. "_id" : "example/test2",
  19. "_rev" : "_dAzP042--A",
  20. "value" : 2
  21. },
  22. {
  23. "_key" : "test3",
  24. "_id" : "example/test3",
  25. "_rev" : "_dAzP046---",
  26. "value" : 3
  27. },
  28. {
  29. "_key" : "test4",
  30. "_id" : "example/test4",
  31. "_rev" : "_dAzP046--A",
  32. "value" : 4
  33. },
  34. {
  35. "_key" : "test5",
  36. "_id" : "example/test5",
  37. "_rev" : "_dAzP046--C",
  38. "value" : 5
  39. },
  40. {
  41. "_key" : "test6",
  42. "_id" : "example/test6",
  43. "_rev" : "_dAzP046--E",
  44. "value" : 6
  45. },
  46. {
  47. "_key" : "test7",
  48. "_id" : "example/test7",
  49. "_rev" : "_dAzP05----",
  50. "value" : 7
  51. },
  52. {
  53. "_key" : "test8",
  54. "_id" : "example/test8",
  55. "_rev" : "_dAzP05---A",
  56. "value" : 8
  57. },
  58. {
  59. "_key" : "test9",
  60. "_id" : "example/test9",
  61. "_rev" : "_dAzP05---C",
  62. "value" : 9
  63. }
  64. ]
  65. }

Insert / Save

Note: since ArangoDB 2.2, insert is an alias for save.

collection.insert(data)
collection.save(data)

Creates a new document in the collection from the given data. The data must be an object. The attributes _id and _rev are ignored and are automatically generated. A unique value for the attribute _key will be automatically generated if not specified. If specified, there must not be a document with the given _key in the collection.

The method returns a document with the attributes _id, _key and _rev. The attribute _id contains the document handle of the newly created document, the attribute _key the document key and the attribute _rev contains the document revision.

collection.insert(data, options)
collection.save(data, options)

Creates a new document in the collection from the given data as above. The optional options parameter must be an object and can be used to specify the following options:

  • waitForSync: One can force synchronization of the document creation operation to disk even in case that the waitForSync flag is been disabled for the entire collection. Thus, the waitForSync option can be used to force synchronization of just specific operations. To use this, set the waitForSync parameter to true. If the waitForSync parameter is not specified or set to false, then the collection’s default waitForSync behavior is applied. The waitForSync parameter cannot be used to disable synchronization for collections that have a default waitForSync value of true.
  • silent: If this flag is set to true, the method does not return any output.
  • returnNew: If this flag is set to true, the complete new document is returned in the output under the attribute new.
  • returnOld: If this flag is set to true, the complete old document is returned in the output under the attribute old. Only available in combination with the overwrite option
  • overwrite: If set to true, the insert becomes a replace-insert. If a document with the same _key exists already the new document is not rejected with unique constraint violated but will replace the old document. Note that operations with overwrite parameter require a _key attribute in the request payload, therefore they can only be performed on collections sharded by _key.
  • overwriteMode: this optional flag can have one of the following values:
    • ignore: if a document with the specified _key value exists already, nothing will be done and no write operation will be carried out (introduced in v3.7.0). The insert operation will return success in this case. This mode does not support returning the old document version using the returnOld attribute. returnNew will only set the new attribute in the response if a new document was inserted.
    • replace: if a document with the specified _key value exists already, it will be overwritten with the specified document value. This mode will also be used when no overwrite mode is specified but the overwrite flag is set to true.
    • update: if a document with the specified _key value exists already, it will be patched (partially updated) with the specified document value (introduced in v3.7.0). The overwrite mode can be further controlled via the keepNull and mergeObjects parameters.
    • conflict: if a document with the specified _key value exists already, return a unique constraint violation error so that the insert operation fails. This is also the default behavior in case the overwrite mode is not set, and the overwrite flag is false or not set either.
  • keepNull: The optional keepNull parameter can be used to modify the behavior when handling null values. Normally, null values are stored in the database. By setting the keepNull parameter to false, this behavior can be changed so that all attributes in data with null values will be removed from the target document. This option controls the update-insert behavior only.
  • mergeObjects: Controls whether objects (not arrays) will be merged if present in both the existing and the patch document. If set to false, the value in the patch document will overwrite the existing document’s value. If set to true, objects will be merged. The default is true. This option controls the update-insert behavior only.

collection.insert(array)

collection.insert(array, options)

These two variants allow to perform the operation on a whole array of arguments. The behavior is exactly as if insert would have been called on all members of the array separately and all results are returned in an array. If an error occurs with any of the documents, no exception is risen! Instead of a document an error object is returned in the result array. The options behave exactly as before.

Changes in 3.0 from 2.8:

The options silent and returnNew are new. The method can now insert multiple documents with one call.

Examples

  1. arangosh> db.example.insert({ Hello : "World" });
  2. arangosh> db.example.insert({ Hello : "World" }, {waitForSync: true});

Show execution results

Hide execution results

  1. {
  2. "_id" : "example/75954",
  3. "_key" : "75954",
  4. "_rev" : "_dAzP1Ai---"
  5. }
  6. {
  7. "_id" : "example/75956",
  8. "_key" : "75956",
  9. "_rev" : "_dAzP1Ai--A"
  10. }
  1. arangosh> db.example.insert([{ Hello : "World" }, {Hello: "there"}])
  2. arangosh> db.example.insert([{ Hello : "World" }, {}], {waitForSync: true});

Show execution results

Hide execution results

  1. [
  2. {
  3. "_id" : "example/75941",
  4. "_key" : "75941",
  5. "_rev" : "_dAzP1AC---"
  6. },
  7. {
  8. "_id" : "example/75942",
  9. "_key" : "75942",
  10. "_rev" : "_dAzP1AC--A"
  11. }
  12. ]
  13. [
  14. {
  15. "_id" : "example/75944",
  16. "_key" : "75944",
  17. "_rev" : "_dAzP1AC--C"
  18. },
  19. {
  20. "_id" : "example/75945",
  21. "_key" : "75945",
  22. "_rev" : "_dAzP1AC--E"
  23. }
  24. ]
  1. arangosh> db.example.insert({ _key : "666", Hello : "World" });
  2. arangosh> db.example.insert({ _key : "666", Hello : "Universe" }, {overwrite: true, returnOld: true});

Show execution results

Hide execution results

  1. {
  2. "_id" : "example/666",
  3. "_key" : "666",
  4. "_rev" : "_dAzP1B----"
  5. }
  6. {
  7. "_id" : "example/666",
  8. "_key" : "666",
  9. "_rev" : "_dAzP1B---A",
  10. "_oldRev" : "_dAzP1B----",
  11. "old" : {
  12. "_key" : "666",
  13. "_id" : "example/666",
  14. "_rev" : "_dAzP1B----",
  15. "Hello" : "World"
  16. }
  17. }

Replace

collection.replace(selector, data)

Replaces an existing document described by the selector, which must be an object containing the _id or _key attribute. There must be a document with that _id or _key in the current collection. This document is then replaced with the data given as second argument. Any attribute _id, _key or _rev in data is ignored.

The method returns a document with the attributes _id, _key, _rev and _oldRev. The attribute _id contains the document handle of the updated document, the attribute _rev contains the document revision of the updated document, the attribute _oldRev contains the revision of the old (now replaced) document.

If the selector contains a _rev attribute, the method first checks that the specified revision is the current revision of that document. If not, there is a conflict, and an error is thrown.

collection.replace(selector, data, options)

As before, but options must be an object that can contain the following boolean attributes:

  • waitForSync: One can force synchronization of the document creation operation to disk even in case that the waitForSync flag is been disabled for the entire collection. Thus, the waitForSync option can be used to force synchronization of just specific operations. To use this, set the waitForSync parameter to true. If the waitForSync parameter is not specified or set to false, then the collection’s default waitForSync behavior is applied. The waitForSync parameter cannot be used to disable synchronization for collections that have a default waitForSync value of true.
  • overwrite: If this flag is set to true, a _rev attribute in the selector is ignored.
  • returnNew: If this flag is set to true, the complete new document is returned in the output under the attribute new.
  • returnOld: If this flag is set to true, the complete previous revision of the document is returned in the output under the attribute old.
  • silent: If this flag is set to true, no output is returned.

collection.replace(document-handle, data)

collection.replace(document-handle, data, options)

As before. Instead of selector a document-handle can be passed as first argument. No revision precondition is tested.

collection.replace(document-key, data)

collection.replace(document-key, data, options)

As before. Instead of selector a document-key can be passed as first argument. No revision precondition is tested.

collection.replace(selectorarray, dataarray)

collection.replace(selectorarray, dataarray, options)

These two variants allow to perform the operation on a whole array of selector/data pairs. The two arrays given as selectorarray and dataarray must have the same length. The behavior is exactly as if replace would have been called on all respective members of the two arrays and all results are returned in an array. If an error occurs with any of the documents, no exception is risen! Instead of a document an error object is returned in the result array. The options behave exactly as before.

Examples

Create and update a document:

  1. arangosh> a1 = db.example.insert({ a : 1 });
  2. arangosh> a2 = db.example.replace(a1, { a : 2 });
  3. arangosh> a3 = db.example.replace(a1, { a : 3 });

Show execution results

Hide execution results

  1. {
  2. "_id" : "example/76083",
  3. "_key" : "76083",
  4. "_rev" : "_dAzP1E---A"
  5. }
  6. {
  7. "_id" : "example/76083",
  8. "_key" : "76083",
  9. "_rev" : "_dAzP1E---C",
  10. "_oldRev" : "_dAzP1E---A"
  11. }
  12. [ArangoError 1200: conflict]

Use a document handle:

  1. arangosh> a1 = db.example.insert({ a : 1 });
  2. arangosh> a2 = db.example.replace("example/3903044", { a : 2 });

Show execution results

Hide execution results

  1. {
  2. "_id" : "example/3903045",
  3. "_key" : "3903045",
  4. "_rev" : "_dAzP1EO--C"
  5. }
  6. {
  7. "_id" : "example/3903044",
  8. "_key" : "3903044",
  9. "_rev" : "_dAzP1ES---",
  10. "_oldRev" : "_dAzP1EO--A"
  11. }

Changes in 3.0 from 2.8:

The options silent, returnNew and returnOld are new. The method can now replace multiple documents with one call.

Update

collection.update(selector, data)

Updates an existing document described by the selector, which must be an object containing the _id or _key attribute. There must be a document with that _id or _key in the current collection. This document is then patched with the data given as second argument. Any attribute _id, _key or _rev in data is ignored.

The method returns a document with the attributes _id, _key, _rev and _oldRev. The attribute _id contains the document handle of the updated document, the attribute _rev contains the document revision of the updated document, the attribute _oldRev contains the revision of the old (now updated) document.

If the selector contains a _rev attribute, the method first checks that the specified revision is the current revision of that document. If not, there is a conflict, and an error is thrown.

collection.update(selector, data, options)

As before, but options must be an object that can contain the following boolean attributes:

  • waitForSync: One can force synchronization of the document creation operation to disk even in case that the waitForSync flag is been disabled for the entire collection. Thus, the waitForSync option can be used to force synchronization of just specific operations. To use this, set the waitForSync parameter to true. If the waitForSync parameter is not specified or set to false, then the collection’s default waitForSync behavior is applied. The waitForSync parameter cannot be used to disable synchronization for collections that have a default waitForSync value of true.
  • overwrite: If this flag is set to true, a _rev attribute in the selector is ignored.
  • returnNew: If this flag is set to true, the complete new document is returned in the output under the attribute new.
  • returnOld: If this flag is set to true, the complete previous revision of the document is returned in the output under the attribute old.
  • silent: If this flag is set to true, no output is returned.
  • keepNull: The optional keepNull parameter can be used to modify the behavior when handling null values. Normally, null values are stored in the database. By setting the keepNull parameter to false, this behavior can be changed so that all attributes in data with null values will be removed from the target document.
  • mergeObjects: Controls whether objects (not arrays) will be merged if present in both the existing and the patch document. If set to false, the value in the patch document will overwrite the existing document’s value. If set to true, objects will be merged. The default is true.

collection.update(document-handle, data)

collection.update(document-handle, data, options)

As before. Instead of selector a document-handle can be passed as first argument. No revision precondition is tested.

collection.update(document-key, data)

collection.update(document-key, data, options)

As before. Instead of selector a document-key can be passed as first argument. No revision precondition is tested.

collection.update(selectorarray, dataarray)

collection.update(selectorarray, dataarray, options)

These two variants allow to perform the operation on a whole array of selector/data pairs. The two arrays given as selectorarray and dataarray must have the same length. The behavior is exactly as if update would have been called on all respective members of the two arrays and all results are returned in an array. If an error occurs with any of the documents, no exception is risen! Instead of a document an error object is returned in the result array. The options behave exactly as before.

Examples

Create and update a document:

  1. arangosh> a1 = db.example.insert({"a" : 1});
  2. arangosh> a2 = db.example.update(a1, {"b" : 2, "c" : 3});
  3. arangosh> a3 = db.example.update(a1, {"d" : 4});
  4. arangosh> a4 = db.example.update(a2, {"e" : 5, "f" : 6 });
  5. arangosh> db.example.document(a4);
  6. arangosh> a5 = db.example.update(a4, {"a" : 1, c : 9, e : 42 });
  7. arangosh> db.example.document(a5);

Show execution results

Hide execution results

  1. {
  2. "_id" : "example/76163",
  3. "_key" : "76163",
  4. "_rev" : "_dAzP1G---A"
  5. }
  6. {
  7. "_id" : "example/76163",
  8. "_key" : "76163",
  9. "_rev" : "_dAzP1GC---",
  10. "_oldRev" : "_dAzP1G---A"
  11. }
  12. [ArangoError 1200: conflict]
  13. {
  14. "_id" : "example/76163",
  15. "_key" : "76163",
  16. "_rev" : "_dAzP1GG---",
  17. "_oldRev" : "_dAzP1GC---"
  18. }
  19. {
  20. "_key" : "76163",
  21. "_id" : "example/76163",
  22. "_rev" : "_dAzP1GG---",
  23. "a" : 1,
  24. "c" : 3,
  25. "b" : 2,
  26. "f" : 6,
  27. "e" : 5
  28. }
  29. {
  30. "_id" : "example/76163",
  31. "_key" : "76163",
  32. "_rev" : "_dAzP1GK---",
  33. "_oldRev" : "_dAzP1GG---"
  34. }
  35. {
  36. "_key" : "76163",
  37. "_id" : "example/76163",
  38. "_rev" : "_dAzP1GK---",
  39. "a" : 1,
  40. "c" : 9,
  41. "b" : 2,
  42. "f" : 6,
  43. "e" : 42
  44. }

Use a document handle:

  1. arangosh> a1 = db.example.insert({"a" : 1});
  2. arangosh> a2 = db.example.update("example/18612115", { "x" : 1, "y" : 2 });

Show execution results

Hide execution results

  1. {
  2. "_id" : "example/18612116",
  3. "_key" : "18612116",
  4. "_rev" : "_dAzP1Ha--A"
  5. }
  6. {
  7. "_id" : "example/18612115",
  8. "_key" : "18612115",
  9. "_rev" : "_dAzP1Ha--C",
  10. "_oldRev" : "_dAzP1Ha---"
  11. }

Use the keepNull parameter to remove attributes with null values:

  1. arangosh> db.example.insert({"a" : 1});
  2. arangosh> db.example.update("example/19988371",
  3. ........> { "b" : null, "c" : null, "d" : 3 });
  4. arangosh> db.example.document("example/19988371");
  5. arangosh> db.example.update("example/19988371", { "a" : null }, false, false);
  6. arangosh> db.example.document("example/19988371");
  7. arangosh> db.example.update("example/19988371",
  8. ........> { "b" : null, "c": null, "d" : null }, false, false);
  9. arangosh> db.example.document("example/19988371");

Show execution results

Hide execution results

  1. {
  2. "_id" : "example/19988372",
  3. "_key" : "19988372",
  4. "_rev" : "_dAzP1G6--A"
  5. }
  6. {
  7. "_id" : "example/19988371",
  8. "_key" : "19988371",
  9. "_rev" : "_dAzP1H----",
  10. "_oldRev" : "_dAzP1G6---"
  11. }
  12. {
  13. "_key" : "19988371",
  14. "_id" : "example/19988371",
  15. "_rev" : "_dAzP1H----",
  16. "b" : null,
  17. "d" : 3,
  18. "c" : null
  19. }
  20. {
  21. "_id" : "example/19988371",
  22. "_key" : "19988371",
  23. "_rev" : "_dAzP1HG---",
  24. "_oldRev" : "_dAzP1H----"
  25. }
  26. {
  27. "_key" : "19988371",
  28. "_id" : "example/19988371",
  29. "_rev" : "_dAzP1HG---",
  30. "b" : null,
  31. "d" : 3,
  32. "c" : null
  33. }
  34. {
  35. "_id" : "example/19988371",
  36. "_key" : "19988371",
  37. "_rev" : "_dAzP1HG--A",
  38. "_oldRev" : "_dAzP1HG---"
  39. }
  40. {
  41. "_key" : "19988371",
  42. "_id" : "example/19988371",
  43. "_rev" : "_dAzP1HG--A"
  44. }

Patching array values:

  1. arangosh> db.example.insert({"a" : { "one" : 1, "two" : 2, "three" : 3 },
  2. ........> "b" : { }});
  3. arangosh> db.example.update("example/20774803", {"a" : { "four" : 4 },
  4. ........> "b" : { "b1" : 1 }});
  5. arangosh> db.example.document("example/20774803");
  6. arangosh> db.example.update("example/20774803", { "a" : { "one" : null },
  7. ........> "b" : null },
  8. ........> false, false);
  9. arangosh> db.example.document("example/20774803");

Show execution results

Hide execution results

  1. {
  2. "_id" : "example/20774804",
  3. "_key" : "20774804",
  4. "_rev" : "_dAzP1Ge--A"
  5. }
  6. {
  7. "_id" : "example/20774803",
  8. "_key" : "20774803",
  9. "_rev" : "_dAzP1Gi---",
  10. "_oldRev" : "_dAzP1Ge---"
  11. }
  12. {
  13. "_key" : "20774803",
  14. "_id" : "example/20774803",
  15. "_rev" : "_dAzP1Gi---",
  16. "b" : {
  17. "b1" : 1
  18. },
  19. "a" : {
  20. "four" : 4
  21. }
  22. }
  23. {
  24. "_id" : "example/20774803",
  25. "_key" : "20774803",
  26. "_rev" : "_dAzP1Gm---",
  27. "_oldRev" : "_dAzP1Gi---"
  28. }
  29. {
  30. "_key" : "20774803",
  31. "_id" : "example/20774803",
  32. "_rev" : "_dAzP1Gm---",
  33. "a" : {
  34. "four" : 4
  35. }
  36. }

Changes in 3.0 from 2.8:

The options silent, returnNew and returnOld are new. The method can now update multiple documents with one call.

Remove

collection.remove(selector)

Removes a document described by the selector, which must be an object containing the _id or _key attribute. There must be a document with that _id or _key in the current collection. This document is then removed.

The method returns a document with the attributes _id, _key and _rev. The attribute _id contains the document handle of the removed document, the attribute _rev contains the document revision of the removed document.

If the selector contains a _rev attribute, the method first checks that the specified revision is the current revision of that document. If not, there is a conflict, and an error is thrown.

collection.remove(selector, options)

As before, but options must be an object that can contain the following boolean attributes:

  • waitForSync: One can force synchronization of the document creation operation to disk even in case that the waitForSync flag is been disabled for the entire collection. Thus, the waitForSync option can be used to force synchronization of just specific operations. To use this, set the waitForSync parameter to true. If the waitForSync parameter is not specified or set to false, then the collection’s default waitForSync behavior is applied. The waitForSync parameter cannot be used to disable synchronization for collections that have a default waitForSync value of true.
  • overwrite: If this flag is set to true, a _rev attribute in the selector is ignored.
  • returnOld: If this flag is set to true, the complete previous revision of the document is returned in the output under the attribute old.
  • silent: If this flag is set to true, no output is returned.

collection.remove(document-handle)

collection.remove(document-handle, options)

As before. Instead of selector a document-handle can be passed as first argument. No revision check is performed.

collection.remove(document-key)

collection.remove(document-handle, options)

As before. Instead of selector a document-handle can be passed as first argument. No revision check is performed.

collection.remove(selectorarray)

collection.remove(selectorarray,options)

These two variants allow to perform the operation on a whole array of selectors. The behavior is exactly as if remove would have been called on all members of the array separately and all results are returned in an array. If an error occurs with any of the documents, no exception is risen! Instead of a document an error object is returned in the result array. The options behave exactly as before.

Examples

Remove a document:

  1. arangosh> a1 = db.example.insert({ a : 1 });
  2. arangosh> db.example.document(a1);
  3. arangosh> db.example.remove(a1);
  4. arangosh> db.example.document(a1);

Show execution results

Hide execution results

  1. {
  2. "_id" : "example/75906",
  3. "_key" : "75906",
  4. "_rev" : "_dAzP1_K--A"
  5. }
  6. {
  7. "_key" : "75906",
  8. "_id" : "example/75906",
  9. "_rev" : "_dAzP1_K--A",
  10. "a" : 1
  11. }
  12. {
  13. "_id" : "example/75906",
  14. "_key" : "75906",
  15. "_rev" : "_dAzP1_K--A"
  16. }
  17. [ArangoError 1202: document not found]

Remove a document with a conflict:

  1. arangosh> a1 = db.example.insert({ a : 1 });
  2. arangosh> a2 = db.example.replace(a1, { a : 2 });
  3. arangosh> db.example.remove(a1);
  4. arangosh> db.example.remove(a1, true);
  5. arangosh> db.example.document(a1);

Show execution results

Hide execution results

  1. {
  2. "_id" : "example/75892",
  3. "_key" : "75892",
  4. "_rev" : "_dAzP1-y--A"
  5. }
  6. {
  7. "_id" : "example/75892",
  8. "_key" : "75892",
  9. "_rev" : "_dAzP1-2---",
  10. "_oldRev" : "_dAzP1-y--A"
  11. }
  12. [ArangoError 1200: conflict]
  13. {
  14. "_id" : "example/75892",
  15. "_key" : "75892",
  16. "_rev" : "_dAzP1-2---"
  17. }
  18. [ArangoError 1202: document not found]

Changes in 3.0 from 2.8:

The method now returns not only true but information about the removed document(s). The options silent and returnOld are new. The method can now remove multiple documents with one call.

Remove By Keys

collection.removeByKeys(keys)

Looks up the documents in the specified collection using the array of keys provided, and removes all documents from the collection whose keys are contained in the keys array. Keys for which no document can be found in the underlying collection are ignored, and no exception will be thrown for them.

The method will return an object containing the number of removed documents in the removed sub-attribute, and the number of not-removed/ignored documents in the ignored sub-attribute.

This method is deprecated in favour of the array variant of remove.

Examples

  1. arangosh> keys = [ ];
  2. arangosh> for (var i = 0; i < 10; ++i) {
  3. ........> db.example.insert({ _key: "test" + i, value: i });
  4. ........> keys.push("test" + i);
  5. ........> }
  6. arangosh> db.example.removeByKeys(keys);

Show execution results

Hide execution results

  1. [ ]
  2. {
  3. "removed" : 10,
  4. "ignored" : 0
  5. }

Remove By Example

collection.removeByExample(example)

Removes all documents matching an example.

collection.removeByExample(document, waitForSync)

The optional waitForSync parameter can be used to force synchronization of the document deletion operation to disk even in case that the waitForSync flag had been disabled for the entire collection. Thus, the waitForSync parameter can be used to force synchronization of just specific operations. To use this, set the waitForSync parameter to true. If the waitForSync parameter is not specified or set to false, then the collection’s default waitForSync behavior is applied. The waitForSync parameter cannot be used to disable synchronization for collections that have a default waitForSync value of true.

collection.removeByExample(document, waitForSync, limit)

The optional limit parameter can be used to restrict the number of removals to the specified value. If limit is specified but less than the number of documents in the collection, it is undefined which documents are removed.

Examples

  1. arangosh> db.example.removeByExample( {Hello : "world"} );

Show execution results

Hide execution results

  1. 1

Replace By Example

collection.replaceByExample(example, newValue)

Replaces all documents matching an example with a new document body. The entire document body of each document matching the example will be replaced with newValue. The document meta-attributes _id, _key and _rev will not be replaced.

collection.replaceByExample(document, newValue, waitForSync)

The optional waitForSync parameter can be used to force synchronization of the document replacement operation to disk even in case that the waitForSync flag had been disabled for the entire collection. Thus, the waitForSync parameter can be used to force synchronization of just specific operations. To use this, set the waitForSync parameter to true. If the waitForSync parameter is not specified or set to false, then the collection’s default waitForSync behavior is applied. The waitForSync parameter cannot be used to disable synchronization for collections that have a default waitForSync value of true.

collection.replaceByExample(document, newValue, waitForSync, limit)

The optional limit parameter can be used to restrict the number of replacements to the specified value. If limit is specified but less than the number of documents in the collection, it is undefined which documents are replaced.

Examples

  1. arangosh> db.example.insert({ Hello : "world" });
  2. arangosh> db.example.replaceByExample({ Hello: "world" }, {Hello: "mars"}, false, 5);

Show execution results

Hide execution results

  1. {
  2. "_id" : "example/4511",
  3. "_key" : "4511",
  4. "_rev" : "_dAzP-ea---"
  5. }
  6. 1

Update By Example

collection.updateByExample(example, newValue)

Partially updates all documents matching an example with a new document body. Specific attributes in the document body of each document matching the example will be updated with the values from newValue. The document meta-attributes _id, _key and _rev cannot be updated.

Partial update could also be used to append new fields, if there were no old field with same name.

collection.updateByExample(document, newValue, keepNull, waitForSync)

The optional keepNull parameter can be used to modify the behavior when handling null values. Normally, null values are stored in the database. By setting the keepNull parameter to false, this behavior can be changed so that all attributes in data with null values will be removed from the target document.

The optional waitForSync parameter can be used to force synchronization of the document replacement operation to disk even in case that the waitForSync flag had been disabled for the entire collection. Thus, the waitForSync parameter can be used to force synchronization of just specific operations. To use this, set the waitForSync parameter to true. If the waitForSync parameter is not specified or set to false, then the collection’s default waitForSync behavior is applied. The waitForSync parameter cannot be used to disable synchronization for collections that have a default waitForSync value of true.

collection.updateByExample(document, newValue, keepNull, waitForSync, limit)

The optional limit parameter can be used to restrict the number of updates to the specified value. If limit is specified but less than the number of documents in the collection, it is undefined which documents are updated.

collection.updateByExample(document, newValue, options)

Using this variant, the options for the operation can be passed using an object with the following sub-attributes:

  • keepNull
  • waitForSync
  • limit
  • mergeObjects

Examples

  1. arangosh> db.example.insert({ Hello : "world", foo : "bar" });
  2. arangosh> db.example.updateByExample({ Hello: "world" }, { Hello: "foo", World: "bar" }, false);
  3. arangosh> db.example.byExample({ Hello: "foo" }).toArray()

Show execution results

Hide execution results

  1. {
  2. "_id" : "example/4522",
  3. "_key" : "4522",
  4. "_rev" : "_dAzP-e2---"
  5. }
  6. 1
  7. [
  8. {
  9. "_key" : "4522",
  10. "_id" : "example/4522",
  11. "_rev" : "_dAzP-e6---",
  12. "Hello" : "foo",
  13. "foo" : "bar",
  14. "World" : "bar"
  15. }
  16. ]

Collection type

collection.type()

Returns the type of a collection. Possible values are:

  • 2: document collection
  • 3: edge collection

Convert a document key to a document id

collection.documentId(documentKey)

Qualifies the given document key with this collection’s name to derive a valid document id.

Throws if the document key is invalid. Note that this method does not check whether the document already exists in this collection.

Edges

Edges are normal documents that always contain a _from and a _to attribute. Therefore, you can use the document methods to operate on edges. The following methods, however, are specific to edges.

edge-collection.edges(vertex)

The edges operator finds all edges starting from (outbound) or ending in (inbound) vertex.

edge-collection.edges(vertices)

The edges operator finds all edges starting from (outbound) or ending in (inbound) a document from vertices, which must be a list of documents or document handles.

  1. arangosh> db._create("vertex");
  2. arangosh> db._createEdgeCollection("relation");
  3. arangosh> var myGraph = {};
  4. arangosh> myGraph.v1 = db.vertex.insert({ name : "vertex 1" });
  5. arangosh> myGraph.v2 = db.vertex.insert({ name : "vertex 2" });
  6. arangosh> myGraph.e1 = db.relation.insert(myGraph.v1, myGraph.v2,
  7. ........> { label : "knows"});
  8. arangosh> db._document(myGraph.e1);
  9. arangosh> db.relation.edges(myGraph.e1._id);

Show execution results

Hide execution results

  1. [ArangoCollection 65594, "vertex" (type document, status loaded)]
  2. [ArangoCollection 65599, "relation" (type edge, status loaded)]
  3. {
  4. "_id" : "vertex/65606",
  5. "_key" : "65606",
  6. "_rev" : "_dAzPIGO---"
  7. }
  8. {
  9. "_id" : "vertex/65608",
  10. "_key" : "65608",
  11. "_rev" : "_dAzPIGS---"
  12. }
  13. {
  14. "_id" : "relation/65610",
  15. "_key" : "65610",
  16. "_rev" : "_dAzPIGS--A"
  17. }
  18. {
  19. "_key" : "65610",
  20. "_id" : "relation/65610",
  21. "_from" : "vertex/65606",
  22. "_to" : "vertex/65608",
  23. "_rev" : "_dAzPIGS--A",
  24. "label" : "knows"
  25. }
  26. [ ]

edge-collection.inEdges(vertex)

The edges operator finds all edges ending in (inbound) vertex.

edge-collection.inEdges(vertices)

The edges operator finds all edges ending in (inbound) a document from vertices, which must a list of documents or document handles.

Examples

  1. arangosh> db._create("vertex");
  2. arangosh> db._createEdgeCollection("relation");
  3. arangosh> myGraph.v1 = db.vertex.insert({ name : "vertex 1" });
  4. arangosh> myGraph.v2 = db.vertex.insert({ name : "vertex 2" });
  5. arangosh> myGraph.e1 = db.relation.insert(myGraph.v1, myGraph.v2,
  6. ........> { label : "knows"});
  7. arangosh> db._document(myGraph.e1);
  8. arangosh> db.relation.inEdges(myGraph.v1._id);
  9. arangosh> db.relation.inEdges(myGraph.v2._id);

Show execution results

Hide execution results

  1. [ArangoCollection 65618, "vertex" (type document, status loaded)]
  2. [ArangoCollection 65623, "relation" (type edge, status loaded)]
  3. {
  4. "_id" : "vertex/65630",
  5. "_key" : "65630",
  6. "_rev" : "_dAzPIG2---"
  7. }
  8. {
  9. "_id" : "vertex/65632",
  10. "_key" : "65632",
  11. "_rev" : "_dAzPIG2--A"
  12. }
  13. {
  14. "_id" : "relation/65634",
  15. "_key" : "65634",
  16. "_rev" : "_dAzPIG6---"
  17. }
  18. {
  19. "_key" : "65634",
  20. "_id" : "relation/65634",
  21. "_from" : "vertex/65630",
  22. "_to" : "vertex/65632",
  23. "_rev" : "_dAzPIG6---",
  24. "label" : "knows"
  25. }
  26. [ ]
  27. [
  28. {
  29. "_key" : "65634",
  30. "_id" : "relation/65634",
  31. "_from" : "vertex/65630",
  32. "_to" : "vertex/65632",
  33. "_rev" : "_dAzPIG6---",
  34. "label" : "knows"
  35. }
  36. ]

edge-collection.outEdges(vertex)

The edges operator finds all edges starting from (outbound) vertices.

edge-collection.outEdges(vertices)

The edges operator finds all edges starting from (outbound) a document from vertices, which must a list of documents or document handles.

Examples

  1. arangosh> db._create("vertex");
  2. arangosh> db._createEdgeCollection("relation");
  3. arangosh> myGraph.v1 = db.vertex.insert({ name : "vertex 1" });
  4. arangosh> myGraph.v2 = db.vertex.insert({ name : "vertex 2" });
  5. arangosh> myGraph.e1 = db.relation.insert(myGraph.v1, myGraph.v2,
  6. ........> { label : "knows"});
  7. arangosh> db._document(myGraph.e1);
  8. arangosh> db.relation.outEdges(myGraph.v1._id);
  9. arangosh> db.relation.outEdges(myGraph.v2._id);

Show execution results

Hide execution results

  1. [ArangoCollection 65644, "vertex" (type document, status loaded)]
  2. [ArangoCollection 65649, "relation" (type edge, status loaded)]
  3. {
  4. "_id" : "vertex/65656",
  5. "_key" : "65656",
  6. "_rev" : "_dAzPIHe---"
  7. }
  8. {
  9. "_id" : "vertex/65658",
  10. "_key" : "65658",
  11. "_rev" : "_dAzPIHe--A"
  12. }
  13. {
  14. "_id" : "relation/65660",
  15. "_key" : "65660",
  16. "_rev" : "_dAzPIHi---"
  17. }
  18. {
  19. "_key" : "65660",
  20. "_id" : "relation/65660",
  21. "_from" : "vertex/65656",
  22. "_to" : "vertex/65658",
  23. "_rev" : "_dAzPIHi---",
  24. "label" : "knows"
  25. }
  26. [
  27. {
  28. "_key" : "65660",
  29. "_id" : "relation/65660",
  30. "_from" : "vertex/65656",
  31. "_to" : "vertex/65658",
  32. "_rev" : "_dAzPIHi---",
  33. "label" : "knows"
  34. }
  35. ]
  36. [ ]

Misc

collection.iterate(iterator, options)

Iterates over some elements of the collection and apply the function iterator to the elements. The function will be called with the document as first argument and the current number (starting with 0) as second argument.

options must be an object with the following attributes:

  • limit (optional, default none): use at most limit documents.

  • probability (optional, default all): a number between 0 and 1. Documents are chosen with this probability.

Examples

  1. arangosh> for (i = -90; i <= 90; i += 10) {
  2. ........> for (j = -180; j <= 180; j += 10) {
  3. ........> db.example.insert({ name : "Name/" + i + "/" + j,
  4. ........> home : [ i, j ],
  5. ........> work : [ -i, -j ] });
  6. ........> }
  7. ........> }
  8. ........>
  9. arangosh> db.example.ensureIndex({ type: "geo", fields: [ "home" ] });
  10. arangosh> items = db.example.getIndexes().map(function(x) { return x.id; });
  11. ........> db.example.index(items[1]);

Show execution results

Hide execution results

  1. {
  2. "bestIndexedLevel" : 17,
  3. "fields" : [
  4. "home"
  5. ],
  6. "geoJson" : false,
  7. "id" : "example/75027",
  8. "isNewlyCreated" : true,
  9. "maxNumCoverCells" : 8,
  10. "name" : "idx_1712165131535777792",
  11. "sparse" : true,
  12. "type" : "geo",
  13. "unique" : false,
  14. "worstIndexedLevel" : 4,
  15. "code" : 201
  16. }
  17. [
  18. "example/0",
  19. "example/75027"
  20. ]