Collection Methods

All

collection.all()

Fetches all documents from a collection and returns a cursor. You can usetoArray, next, or hasNext to access the result. The resultcan 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

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

Hide execution results

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

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

Hide execution results

Query by example

collection.byExample(example)

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

You can use toArray, next, or hasNext to access theresult. 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 attributea 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

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

Hide execution results

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

  1. {
  2. "_id" : "users/172",
  3. "_key" : "172",
  4. "_rev" : "_ZP4O6Oe---"
  5. }
  6. {
  7. "_id" : "users/174",
  8. "_key" : "174",
  9. "_rev" : "_ZP4O6Oe--A"
  10. }
  11. {
  12. "_id" : "users/176",
  13. "_key" : "176",
  14. "_rev" : "_ZP4O6Oi---"
  15. }
  16. {
  17. "_key" : "176",
  18. "_id" : "users/176",
  19. "_rev" : "_ZP4O6Oi---",
  20. "name" : "Angela"
  21. }

Hide execution results

First Example

collection.firstExample(example)

Returns some document of a collection that matches the specifiedexample. 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

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

Hide execution results

Range

collection.range(attribute, left, right)

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

You can use toArray, next, or hasNext to access theresult. 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 preferredway for retrieving documents from a collection within a specific rangeis 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

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

Hide execution results

Closed range

collection.closedRange(attribute, left, right)

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

You can use toArray, next, or hasNext to access theresult. 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 preferredway for retrieving documents from a collection within a specific rangeis 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

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

Hide execution results

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

  1. 0

Hide execution results

toArray

collection.toArray()

Converts the collection into an array of documents. Never use this callin a production environment as it will basically create a copy of yourcollection in RAM which will use resources depending on the number and sizeof 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 returnsthe document if it can be found. If both attributes are given,the id takes precedence, it is an error, if the collection partof the __id does not match the collection.

An error is thrown if rev_ is specified but the document found has adifferent revision already. An error is also thrown if no document existswith the given id or __key value.

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

collection.document(document-handle)

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

collection.document(document-key)

As before. Instead of object a document-key can be passed asfirst 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 membersof the array separately and all results are returned in an array. If an erroroccurs with any of the documents, no exception is risen! Instead of a documentan 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

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

Hide execution results

Returns the document for a document-key:

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

Show execution results

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

Hide execution results

Returns the document for an object:

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

Show execution results

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

Hide execution results

Returns the document for an array of two keys:

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

Show execution results

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

Hide execution results

An error is raised if the document is unknown:

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

Show execution results

  1. [ArangoError 1202: document not found]

Hide execution results

An error is raised if the handle is invalid:

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

Show execution results

  1. [ArangoError 1205: illegal document handle]

Hide execution results

Changes in 3.0 from 2.8:

document can now query multiple documents with one call.

Exists

checks whether a document existscollection.exists(object)

The exists method determines whether a document exists given an objectobject containing the id_ or key attribute. If both attributesare given, the __id takes precedence, it is an error, if the collectionpart of the _id does not match the collection.

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

Instead of returning the found document or an error, this method willonly return an object with the attributes id_, key and __rev, orfalse if no document with the given id_ or key_ exists. It canthus be used for easy existence checks.

This method will throw an error if used improperly, e.g. when calledwith a non-document handle, a non-document, or when a cross-collectionrequest is performed.

collection.exists(document-handle)

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

collection.exists(document-key)

As before. Instead of object a document-key can be passed asfirst 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 allmembers of the array separately and all results are returned in an array. If an erroroccurs with any of the documents, the operation stops immediately returningonly an error object.

Changes in 3.0 from 2.8:

In the case of a revision mismatch exists now throws an error insteadof simply returning false. This is to make it possible to tell thedifference 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 ofkeys provided. All documents for which a matching key was specified inthe keys array and that exist in the collection will be returned. Keysfor which no document can be found in the underlying collection areignored, 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

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

Hide execution results

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. Thedata must be an object. The attributes id_ and rev are ignoredand are automatically generated. A unique value for the attribute key_will be automatically generated if not specified. If specified, theremust 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 newlycreated document, the attribute key the document key and theattribute __rev contains the document revision.

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

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

  • waitForSync: One can forcesynchronization of the document creation operation to disk even incase that the waitForSync flag is been disabled for the entirecollection. Thus, the waitForSync option can be used to forcesynchronization of just specific operations. To use this, set thewaitForSync parameter to true. If the waitForSync parameteris not specified or set to false, then the collection’s defaultwaitForSync behavior is applied. The waitForSync parametercannot be used to disable synchronization for collections that havea default waitForSync value of true.
  • silent: If this flag is set to true, the method does not returnany output.
  • overwrite: If set to true, the insert becomes a replace-insert.If a document with the same _key already exists the new documentis not rejected with unique constraint violated but will replacethe old document.
  • returnNew: If this flag is set to true, the complete new documentis returned in the output under the attribute new.
  • returnOld: If this flag is set to true, the complete old documentis returned in the output under the attribute old. Only available in combination with the overwrite optioncollection.insert(array)

collection.insert(array, options)

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

Changes in 3.0 from 2.8:

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

Examples

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

Show execution results

  1. {
  2. "_id" : "example/73449",
  3. "_key" : "73449",
  4. "_rev" : "_ZP4PTni---"
  5. }
  6. {
  7. "_id" : "example/73451",
  8. "_key" : "73451",
  9. "_rev" : "_ZP4PTnm---"
  10. }

Hide execution results

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

Show execution results

  1. [
  2. {
  3. "_id" : "example/73436",
  4. "_key" : "73436",
  5. "_rev" : "_ZP4PTmm---"
  6. },
  7. {
  8. "_id" : "example/73437",
  9. "_key" : "73437",
  10. "_rev" : "_ZP4PTmm--A"
  11. }
  12. ]
  13. [
  14. {
  15. "_id" : "example/73439",
  16. "_key" : "73439",
  17. "_rev" : "_ZP4PTmm--C"
  18. },
  19. {
  20. "_id" : "example/73440",
  21. "_key" : "73440",
  22. "_rev" : "_ZP4PTmm--E"
  23. }
  24. ]

Hide execution results

  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

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

Hide execution results

Replace

collection.replace(selector, data)

Replaces an existing document described by the selector, which mustbe an object containing the id_ or key attribute. There must bea document with that __id or key in the current collection. Thisdocument 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 theupdated document, the attribute rev contains the document revision ofthe updated document, the attribute __oldRev contains the revision ofthe old (now replaced) document.

If the selector contains a _rev attribute, the method first checksthat 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 followingboolean attributes:

  • waitForSync: One can forcesynchronization of the document creation operation to disk even incase that the waitForSync flag is been disabled for the entirecollection. Thus, the waitForSync option can be used to forcesynchronization of just specific operations. To use this, set thewaitForSync parameter to true. If the waitForSync parameteris not specified or set to false, then the collection’s defaultwaitForSync behavior is applied. The waitForSync parametercannot be used to disable synchronization for collections that havea default waitForSync value of true.
  • overwrite: If this flag is set to true, a _rev attribute inthe selector is ignored.
  • returnNew: If this flag is set to true, the complete new documentis returned in the output under the attribute new.
  • returnOld: If this flag is set to true, the complete previousrevision of the document is returned in the output under theattribute 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 asfirst 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 asfirst 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 ofselector/data pairs. The two arrays given as selectorarray and dataarray_must have the same length. The behavior is exactly as if _replace would havebeen called on all respective members of the two arrays and all results arereturned in an array. If an error occurs with any of the documents, noexception is risen! Instead of a document an error object is returned in theresult 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

  1. {
  2. "_id" : "example/73576",
  3. "_key" : "73576",
  4. "_rev" : "_ZP4PTsS--A"
  5. }
  6. {
  7. "_id" : "example/73576",
  8. "_key" : "73576",
  9. "_rev" : "_ZP4PTsW--_",
  10. "_oldRev" : "_ZP4PTsS--A"
  11. }
  12. [ArangoError 1200: precondition failed]

Hide execution results

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

  1. {
  2. "_id" : "example/3903045",
  3. "_key" : "3903045",
  4. "_rev" : "_ZP4PTsu---"
  5. }
  6. {
  7. "_id" : "example/3903044",
  8. "_key" : "3903044",
  9. "_rev" : "_ZP4PTsu--B",
  10. "_oldRev" : "_ZP4PTsq---"
  11. }

Hide execution results

Changes in 3.0 from 2.8:

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

Update

collection.update(selector, data)

Updates an existing document described by the selector, which mustbe an object containing the id_ or key attribute. There must bea document with that __id or key in the current collection. Thisdocument 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 theupdated document, the attribute rev contains the document revision ofthe updated document, the attribute __oldRev contains the revision ofthe old (now updated) document.

If the selector contains a _rev attribute, the method first checksthat 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 followingboolean attributes:

  • waitForSync: One can forcesynchronization of the document creation operation to disk even incase that the waitForSync flag is been disabled for the entirecollection. Thus, the waitForSync option can be used to forcesynchronization of just specific operations. To use this, set thewaitForSync parameter to true. If the waitForSync parameteris not specified or set to false, then the collection’s defaultwaitForSync behavior is applied. The waitForSync parametercannot be used to disable synchronization for collections that havea default waitForSync value of true.
  • overwrite: If this flag is set to true, a _rev attribute inthe selector is ignored.
  • returnNew: If this flag is set to true, the complete new documentis returned in the output under the attribute new.
  • returnOld: If this flag is set to true, the complete previousrevision of the document is returned in the output under theattribute old.
  • silent: If this flag is set to true, no output is returned.
  • keepNull: The optional keepNull parameter can be used to modifythe behavior when handling null values. Normally, null valuesare stored in the database. By setting the keepNull parameter tofalse, this behavior can be changed so that all attributes indata with null values will be removed from the target document.
  • mergeObjects: Controls whether objects (not arrays) will bemerged if present in both the existing and the patch document. Ifset to false, the value in the patch document will overwrite theexisting 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 asfirst 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 asfirst 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 ofselector/data pairs. The two arrays given as selectorarray and dataarray_must have the same length. The behavior is exactly as if _update would havebeen called on all respective members of the two arrays and all results arereturned in an array. If an error occurs with any of the documents, noexception is risen! Instead of a document an error object is returned in theresult 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

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

Hide execution results

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

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

Hide execution results

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

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

Hide execution results

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

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

Hide execution results

Changes in 3.0 from 2.8:

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

Remove

collection.remove(selector)

Removes a document described by the selector, which must be an objectcontaining the id_ or key attribute. There must be a document withthat __id or _key in the current collection. This document is thenremoved.

The method returns a document with the attributes id_, key and __rev.The attribute id_ contains the document handle of theremoved document, the attribute rev_ contains the document revision ofthe removed document.

If the selector contains a _rev attribute, the method first checksthat 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 followingboolean attributes:

  • waitForSync: One can forcesynchronization of the document creation operation to disk even incase that the waitForSync flag is been disabled for the entirecollection. Thus, the waitForSync option can be used to forcesynchronization of just specific operations. To use this, set thewaitForSync parameter to true. If the waitForSync parameteris not specified or set to false, then the collection’s defaultwaitForSync behavior is applied. The waitForSync parametercannot be used to disable synchronization for collections that havea default waitForSync value of true.
  • overwrite: If this flag is set to true, a _rev attribute inthe selector is ignored.
  • returnOld: If this flag is set to true, the complete previousrevision of the document is returned in the output under theattribute 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 asfirst 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 asfirst 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 ofselectors. The behavior is exactly as if remove would have been called on allmembers of the array separately and all results are returned in an array. If anerror occurs with any of the documents, no exception is risen! Instead of adocument an error object is returned in the result array. The options behaveexactly 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

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

Hide execution results

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

  1. {
  2. "_id" : "example/73389",
  3. "_key" : "73389",
  4. "_rev" : "_ZP4PTl----"
  5. }
  6. {
  7. "_id" : "example/73389",
  8. "_key" : "73389",
  9. "_rev" : "_ZP4PTlC--_",
  10. "_oldRev" : "_ZP4PTl----"
  11. }
  12. [ArangoError 1200: precondition failed]
  13. {
  14. "_id" : "example/73389",
  15. "_key" : "73389",
  16. "_rev" : "_ZP4PTlC--_"
  17. }
  18. [ArangoError 1202: document not found]

Hide execution results

Changes in 3.0 from 2.8:

The method now returns not only true but information about the removeddocument(s). The options silent and returnOld are new. The methodcan 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 keysprovided, and removes all documents from the collection whose keys arecontained in the keys array. Keys for which no document can be found inthe underlying collection are ignored, and no exception will be thrown forthem.

The method will return an object containing the number of removed documentsin the removed sub-attribute, and the number of not-removed/ignoreddocuments 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

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

Hide execution results

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 synchronizationof the document deletion operation to disk even in case that thewaitForSync flag had been disabled for the entire collection. Thus,the waitForSync parameter can be used to force synchronization of justspecific operations. To use this, set the waitForSync parameter totrue. If the waitForSync parameter is not specified or set tofalse, then the collection’s default waitForSync behavior isapplied. The waitForSync parameter cannot be used to disablesynchronization for collections that have a default waitForSync valueof true.

collection.removeByExample(document, waitForSync, limit)

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

Examples

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

Show execution results

  1. 1

Hide execution results

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 bereplaced 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 synchronizationof the document replacement operation to disk even in case that thewaitForSync flag had been disabled for the entire collection. Thus,the waitForSync parameter can be used to force synchronization of justspecific operations. To use this, set the waitForSync parameter totrue. If the waitForSync parameter is not specified or set tofalse, then the collection’s default waitForSync behavior isapplied. The waitForSync parameter cannot be used to disablesynchronization for collections that have a default waitForSync valueof true.

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

The optional limit parameter can be used to restrict the number ofreplacements to the specified value. If limit is specified but less thanthe number of documents in the collection, it is undefined which documents arereplaced.

Examples

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

Show execution results

  1. {
  2. "_id" : "example/4492",
  3. "_key" : "4492",
  4. "_rev" : "_ZP4O7Ky--_"
  5. }
  6. 1

Hide execution results

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 theexample 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 whenhandling null values. Normally, null values are stored in thedatabase. By setting the keepNull parameter to false, this behaviorcan be changed so that all attributes in data with null values willbe removed from the target document.

The optional waitForSync parameter can be used to force synchronizationof the document replacement operation to disk even in case that thewaitForSync flag had been disabled for the entire collection. Thus,the waitForSync parameter can be used to force synchronization of justspecific operations. To use this, set the waitForSync parameter totrue. If the waitForSync parameter is not specified or set tofalse, then the collection’s default waitForSync behavior isapplied. The waitForSync parameter cannot be used to disablesynchronization for collections that have a default waitForSync valueof true.

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

The optional limit parameter can be used to restrict the number ofupdates to the specified value. If limit is specified but less thanthe number of documents in the collection, it is undefined which documents areupdated.

collection.updateByExample(document, newValue, options)

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

  • keepNull
  • waitForSync
  • limit
  • mergeObjectsExamples
  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

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

Hide execution results

Collection type

collection.type()

Returns the type of a collection. Possible values are:

  • 2: document collection
  • 3: edge collection

Get the Version of ArangoDB

db._version()

Returns the server version string. Note that this is not the version of thedatabase.

Examples

  1. arangosh> require("@arangodb").db._version();

Show execution results

  1. 3.4.8

Hide execution results

Edges

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

edge-collection.edges(vertex)

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

edge-collection.edges(vertices)

The edges operator finds all edges starting from (outbound) or endingin (inbound) a document from vertices, which must be a list of documentsor 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

  1. [ArangoCollection 65377, "vertex" (type document, status loaded)]
  2. [ArangoCollection 65382, "relation" (type edge, status loaded)]
  3. {
  4. "_id" : "vertex/65389",
  5. "_key" : "65389",
  6. "_rev" : "_ZP4PFTi---"
  7. }
  8. {
  9. "_id" : "vertex/65391",
  10. "_key" : "65391",
  11. "_rev" : "_ZP4PFTi--A"
  12. }
  13. {
  14. "_id" : "relation/65393",
  15. "_key" : "65393",
  16. "_rev" : "_ZP4PFTm---"
  17. }
  18. {
  19. "_key" : "65393",
  20. "_id" : "relation/65393",
  21. "_from" : "vertex/65389",
  22. "_to" : "vertex/65391",
  23. "_rev" : "_ZP4PFTm---",
  24. "label" : "knows"
  25. }
  26. [ ]

Hide execution results

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 fromvertices, 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

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

Hide execution results

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 documentfrom 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

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

Hide execution results

Misc

collection.iterate(iterator, options)

Iterates over some elements of the collection and apply the functioniterator to the elements. The function will be called with thedocument 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 and1. 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

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

Hide execution results