Working with a Document

Read document

reads a single document

GET /_api/document/{document-handle}

Path Parameters

  • document-handle (required): The handle of the document.

Header Parameters

  • If-None-Match (optional): If the “If-None-Match” header is given, then it must contain exactly one Etag. The document is returned, if it has a different revision than the given Etag. Otherwise an HTTP 304 is returned.

  • If-Match (optional): If the “If-Match” header is given, then it must contain exactly one Etag. The document is returned, if it has the same revision as the given Etag. Otherwise a HTTP 412 is returned.

Returns the document identified by document-handle. The returned document contains three special attributes: _id containing the document handle, _key containing key which uniquely identifies a document in a given collection and _rev containing the revision.

Return codes

  • 200: is returned if the document was found

  • 304: is returned if the “If-None-Match” header is given and the document has the same version

  • 404: is returned if the document or collection was not found

  • 412: is returned if an “If-Match” header is given and the found document has a different version. The response will also contain the found document’s current revision in the _rev attribute. Additionally, the attributes _id and _key will be returned.

Examples

Use a document handle:

shell> curl --header 'accept: application/json' --dump - http://localhost:8529/_api/document/products/69892

HTTP/1.1 OK
etag: "_ZZB__A6--A"
keep-alive: timeout=300
x-content-type-options: nosniff
content-type: application/json

Show response body

Use a document handle and an Etag:

shell> curl --header 'If-None-Match: "_ZZB__CG--A"' --header 'accept: application/json' --dump - http://localhost:8529/_api/document/products/69941

Unknown document handle:

shell> curl --header 'accept: application/json' --dump - http://localhost:8529/_api/document/products/unknownhandle

HTTP/1.1 Not Found
keep-alive: timeout=300
x-content-type-options: nosniff
content-type: application/json

Show response body

Read document header

reads a single document head

HEAD /_api/document/{document-handle}

Path Parameters

  • document-handle (required): The handle of the document.

Header Parameters

  • If-None-Match (optional): If the “If-None-Match” header is given, then it must contain exactly one Etag. If the current document revision is not equal to the specified Etag, an HTTP 200 response is returned. If the current document revision is identical to the specified Etag, then an HTTP 304 is returned.

  • If-Match (optional): If the “If-Match” header is given, then it must contain exactly one Etag. The document is returned, if it has the same revision as the given Etag. Otherwise a HTTP 412 is returned.

Like GET, but only returns the header fields and not the body. You can use this call to get the current revision of a document or check if the document was deleted.

Return codes

  • 200: is returned if the document was found

  • 304: is returned if the “If-None-Match” header is given and the document has the same version

  • 404: is returned if the document or collection was not found

  • 412: is returned if an “If-Match” header is given and the found document has a different version. The response will also contain the found document’s current revision in the Etag header.

Examples

shell> curl -X HEAD --header 'accept: application/json' --dump - http://localhost:8529/_api/document/products/69931

Create document

creates documents

POST /_api/document/{collection}

Path Parameters

  • collection (required): The collection in which the collection is to be created.

Query Parameters

  • collection (optional): The name of the collection. This is only for backward compatibility. In ArangoDB versions < 3.0, the URL path was /_api/document and this query parameter was required. This combination still works, but the recommended way is to specify the collection in the URL path.

  • waitForSync (optional): Wait until document has been synced to disk.

  • returnNew (optional): Additionally return the complete new document under the attribute new in the result.

  • returnOld (optional): Additionally return the complete old document under the attribute old in the result. Only available if the overwrite option is used.

  • silent (optional): If set to true, an empty object will be returned as response. No meta-data will be returned for the created document. This option can be used to save some network traffic.

  • overwrite (optional): If set to true, the insert becomes a replace-insert. If a document with the same _key already exists the new document is not rejected with unique constraint violated but will replace the old document.

Request Body (json)

A JSON representation of a single document.

Creates a new document from the document given in the body, unless there is already a document with the _key given. If no _key is given, a new unique _key is generated automatically.

Possibly given _id and _rev attributes in the body are always ignored, the URL part or the query parameter collection respectively counts.

If the document was created successfully, then the Location header contains the path to the newly created document. The Etag header field contains the revision of the document. Both are only set in the single document case.

If silent is not set to true, the body of the response contains a JSON object with the following attributes:

  • _id contains the document handle of the newly created document
  • _key contains the document key
  • _rev contains the document revision

If the collection parameter waitForSync is false, then the call returns as soon as the document has been accepted. It will not wait until the documents have been synced to disk.

Optionally, the query parameter waitForSync can be used to force synchronization of the document creation operation to disk even in case that the waitForSync flag had been disabled for the entire collection. Thus, the waitForSync query parameter can be used to force synchronization of just this 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 query parameter cannot be used to disable synchronization for collections that have a default waitForSync value of true.

If the query parameter returnNew is true, then, for each generated document, the complete new document is returned under the new attribute in the result.

Return codes

  • 201: is returned if the documents were created successfully and waitForSync was true.

  • 202: is returned if the documents were created successfully and waitForSync was false.

  • 400: is returned if the body does not contain a valid JSON representation of one document. The response body contains an error document in this case.

  • 404: is returned if the collection specified by collection is unknown. The response body contains an error document in this case.

  • 409: is returned in the single document case if a document with the same qualifiers in an indexed attribute conflicts with an already existing document and thus violates that unique constraint. The response body contains an error document in this case.

Examples

Create a document in a collection named products. Note that the revision identifier might or might not by equal to the auto-generated key.

shell> curl -X POST --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/document/products <<EOF
{ "Hello": "World" }
EOF

HTTP/1.1 Created
etag: "_ZZB__-a---"
keep-alive: timeout=300
location: /_db/_system/_api/document/products/69832
x-content-type-options: nosniff
content-type: application/json

Show response body

Create a document in a collection named products with a collection-level waitForSync value of false.

shell> curl -X POST --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/document/products <<EOF
{ "Hello": "World" }
EOF

HTTP/1.1 Accepted
etag: "_ZZB_-9m--A"
keep-alive: timeout=300
location: /_db/_system/_api/document/products/69808
x-content-type-options: nosniff
content-type: application/json

Show response body

Create a document in a collection with a collection-level waitForSync value of false, but using the waitForSync query parameter.

shell> curl -X POST --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/document/products?waitForSync=true <<EOF
{ "Hello": "World" }
EOF

HTTP/1.1 Created
etag: "_ZZB__Ai--A"
keep-alive: timeout=300
location: /_db/_system/_api/document/products/69883
x-content-type-options: nosniff
content-type: application/json

Show response body

Unknown collection name

shell> curl -X POST --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/document/products <<EOF
{ "Hello": "World" }
EOF

HTTP/1.1 Not Found
keep-alive: timeout=300
x-content-type-options: nosniff
content-type: application/json

Show response body

Illegal document

shell> curl -X POST --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/document/products <<EOF
{ 1: "World" }
EOF

HTTP/1.1 Bad Request
keep-alive: timeout=300
x-content-type-options: nosniff
content-type: application/json

Show response body

Use of returnNew:

shell> curl -X POST --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/document/products?returnNew=true <<EOF
{"Hello":"World"}
EOF

HTTP/1.1 Accepted
etag: "_ZZB__AK--A"
keep-alive: timeout=300
location: /_db/_system/_api/document/products/69872
x-content-type-options: nosniff
content-type: application/json

Show response body
shell> curl -X POST --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/document/products <<EOF
{ "Hello": "World", "_key" : "lock" }
EOF

HTTP/1.1 Created
etag: "_ZZB___S---"
keep-alive: timeout=300
location: /_db/_system/_api/document/products/lock
x-content-type-options: nosniff
content-type: application/json

shell> curl -X POST --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/document/products?overwrite=true <<EOF
{ "Hello": "Universe", "_key" : "lock" }
EOF

HTTP/1.1 Created
etag: "_ZZB___i--A"
keep-alive: timeout=300
location: /_db/_system/_api/document/products/lock
x-content-type-options: nosniff
content-type: application/json

Show response body

Replace document

replaces a document

PUT /_api/document/{document-handle}

Path Parameters

  • document-handle (required): This URL parameter must be a document handle.

Query Parameters

  • waitForSync (optional): Wait until document has been synced to disk.

  • ignoreRevs (optional): By default, or if this is set to true, the _rev attributes in the given document is ignored. If this is set to false, then the _rev attribute given in the body document is taken as a precondition. The document is only replaced if the current revision is the one specified.

  • returnOld (optional): Return additionally the complete previous revision of the changed document under the attribute old in the result.

  • returnNew (optional): Return additionally the complete new document under the attribute new in the result.

  • silent (optional): If set to true, an empty object will be returned as response. No meta-data will be returned for the replaced document. This option can be used to save some network traffic.

Header Parameters

  • If-Match (optional): You can conditionally replace a document based on a target revision id by using the if-match HTTP header.

Request Body (json)

A JSON representation of a single document.

Replaces the document with handle with the one in the body, provided there is such a document and no precondition is violated.

The value of the _key attribute as well as attributes used as sharding keys may not be changed.

If the If-Match header is specified and the revision of the document in the database is unequal to the given revision, the precondition is violated.

If If-Match is not given and ignoreRevs is false and there is a _rev attribute in the body and its value does not match the revision of the document in the database, the precondition is violated.

If a precondition is violated, an HTTP 412 is returned.

If the document exists and can be updated, then an HTTP 201 or an HTTP 202 is returned (depending on waitForSync, see below), the Etag header field contains the new revision of the document and the Location header contains a complete URL under which the document can be queried.

Cluster only: The replace documents may contain
values for the collection’s pre-defined shard keys. Values for the shard keys are treated as hints to improve performance. Should the shard keys values be incorrect ArangoDB may answer with a not found error.

Optionally, the query parameter waitForSync 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 query 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 query parameter cannot be used to disable synchronization for collections that have a default waitForSync value of true.

If silent is not set to true, the body of the response contains a JSON object with the information about the handle and the revision. The attribute _id contains the known document-handle of the updated document, _key contains the key which uniquely identifies a document in a given collection, and the attribute _rev contains the new document revision.

If the query parameter returnOld is true, then the complete previous revision of the document is returned under the old attribute in the result.

If the query parameter returnNew is true, then the complete new document is returned under the new attribute in the result.

If the document does not exist, then a HTTP 404 is returned and the body of the response contains an error document.

Return codes

  • 201: is returned if the document was replaced successfully and waitForSync was true.

  • 202: is returned if the document was replaced successfully and waitForSync was false.

  • 400: is returned if the body does not contain a valid JSON representation of a document. The response body contains an error document in this case.

  • 404: is returned if the collection or the document was not found.

  • 412: is returned if the precondition was violated. The response will also contain the found documents’ current revisions in the _rev attributes. Additionally, the attributes _id and _key will be returned.

Examples

Using a document handle

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/document/products/69963 <<EOF
{"Hello": "you"}
EOF

HTTP/1.1 Accepted
etag: "_ZZB__Cq--B"
keep-alive: timeout=300
location: /_db/_system/_api/document/products/69963
x-content-type-options: nosniff
content-type: application/json

Show response body

Unknown document handle

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/document/products/69985 <<EOF
{}
EOF

HTTP/1.1 Not Found
keep-alive: timeout=300
x-content-type-options: nosniff
content-type: application/json

Show response body

Produce a revision conflict

shell> curl -X PUT --header 'If-Match: "_ZZB__C6---"' --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/document/products/69973 <<EOF
{"other":"content"}
EOF

HTTP/1.1 Precondition Failed
etag: "_ZZB__C2--A"
keep-alive: timeout=300
x-content-type-options: nosniff
content-type: application/json

Show response body

Update document

updates a document

PATCH /_api/document/{document-handle}

Path Parameters

  • document-handle (required): This URL parameter must be a document handle.

Query Parameters

  • keepNull (optional): If the intention is to delete existing attributes with the patch command, the URL query parameter keepNull can be used with a value of false. This will modify the behavior of the patch command to remove any attributes from the existing document that are contained in the patch document with an attribute value of null.

  • mergeObjects (optional): 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.

  • waitForSync (optional): Wait until document has been synced to disk.

  • ignoreRevs (optional): By default, or if this is set to true, the _rev attributes in the given document is ignored. If this is set to false, then the _rev attribute given in the body document is taken as a precondition. The document is only updated if the current revision is the one specified.

  • returnOld (optional): Return additionally the complete previous revision of the changed document under the attribute old in the result.

  • returnNew (optional): Return additionally the complete new document under the attribute new in the result.

  • silent (optional): If set to true, an empty object will be returned as response. No meta-data will be returned for the updated document. This option can be used to save some network traffic.

Header Parameters

  • If-Match (optional): You can conditionally update a document based on a target revision id by using the if-match HTTP header.

Request Body (json)

A JSON representation of a document update as an object.

Partially updates the document identified by document-handle. The body of the request must contain a JSON document with the attributes to patch (the patch document). All attributes from the patch document will be added to the existing document if they do not yet exist, and overwritten in the existing document if they do exist there.

The value of the _key attribute as well as attributes used as sharding keys may not be changed.

Setting an attribute value to null in the patch document will cause a value of null to be saved for the attribute by default.

If the If-Match header is specified and the revision of the document in the database is unequal to the given revision, the precondition is violated.

If If-Match is not given and ignoreRevs is false and there is a _rev attribute in the body and its value does not match the revision of the document in the database, the precondition is violated.

If a precondition is violated, an HTTP 412 is returned.

If the document exists and can be updated, then an HTTP 201 or an HTTP 202 is returned (depending on waitForSync, see below), the Etag header field contains the new revision of the document (in double quotes) and the Location header contains a complete URL under which the document can be queried.

Cluster only: The patch document may contain
values for the collection’s pre-defined shard keys. Values for the shard keys are treated as hints to improve performance. Should the shard keys values be incorrect ArangoDB may answer with a not found error

Optionally, the query parameter waitForSync can be used to force synchronization of the updated document operation to disk even in case that the waitForSync flag had been disabled for the entire collection. Thus, the waitForSync query 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 query parameter cannot be used to disable synchronization for collections that have a default waitForSync value of true.

If silent is not set to true, the body of the response contains a JSON object with the information about the handle and the revision. The attribute _id contains the known document-handle of the updated document, _key contains the key which uniquely identifies a document in a given collection, and the attribute _rev contains the new document revision.

If the query parameter returnOld is true, then the complete previous revision of the document is returned under the old attribute in the result.

If the query parameter returnNew is true, then the complete new document is returned under the new attribute in the result.

If the document does not exist, then a HTTP 404 is returned and the body of the response contains an error document.

Return codes

  • 201: is returned if the document was updated successfully and waitForSync was true.

  • 202: is returned if the document was updated successfully and waitForSync was false.

  • 400: is returned if the body does not contain a valid JSON representation of a document. The response body contains an error document in this case.

  • 404: is returned if the collection or the document was not found.

  • 412: is returned if the precondition was violated. The response will also contain the found documents’ current revisions in the _rev attributes. Additionally, the attributes _id and _key will be returned.

Examples

Patches an existing document with new content.

shell> curl -X PATCH --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/document/products/69780 <<EOF
{ 
  "hello" : "world" 
}
EOF

HTTP/1.1 Accepted
etag: "_ZZB_-8e--D"
keep-alive: timeout=300
location: /_db/_system/_api/document/products/69780
x-content-type-options: nosniff
content-type: application/json

shell> curl -X PATCH --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/document/products/69780 <<EOF
{ 
  "numbers" : { 
    "one" : 1, 
    "two" : 2, 
    "three" : 3, 
    "empty" : null 
  } 
}
EOF

HTTP/1.1 Accepted
etag: "_ZZB_-8m--_"
keep-alive: timeout=300
location: /_db/_system/_api/document/products/69780
x-content-type-options: nosniff
content-type: application/json

shell> curl --header 'accept: application/json' --dump - http://localhost:8529/_api/document/products/69780

HTTP/1.1 OK
etag: "_ZZB_-8m--_"
keep-alive: timeout=300
x-content-type-options: nosniff
content-type: application/json

shell> curl -X PATCH --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/document/products/69780?keepNull=false <<EOF
{ 
  "hello" : null, 
  "numbers" : { 
    "four" : 4 
  } 
}
EOF

HTTP/1.1 Accepted
etag: "_ZZB_-8y--_"
keep-alive: timeout=300
location: /_db/_system/_api/document/products/69780
x-content-type-options: nosniff
content-type: application/json

shell> curl --header 'accept: application/json' --dump - http://localhost:8529/_api/document/products/69780

HTTP/1.1 OK
etag: "_ZZB_-8y--_"
keep-alive: timeout=300
x-content-type-options: nosniff
content-type: application/json

Show response body

Merging attributes of an object using mergeObjects:

shell> curl --header 'accept: application/json' --dump - http://localhost:8529/_api/document/products/69794

HTTP/1.1 OK
etag: "_ZZB_-9C--A"
keep-alive: timeout=300
x-content-type-options: nosniff
content-type: application/json

shell> curl -X PATCH --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/document/products/69794?mergeObjects=true <<EOF
{ 
  "inhabitants" : { 
    "indonesia" : 252164800, 
    "brazil" : 203553000 
  } 
}
EOF

shell> curl --header 'accept: application/json' --dump - http://localhost:8529/_api/document/products/69794

HTTP/1.1 OK
etag: "_ZZB_-9K--_"
keep-alive: timeout=300
x-content-type-options: nosniff
content-type: application/json

shell> curl -X PATCH --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/document/products/69794?mergeObjects=false <<EOF
{ 
  "inhabitants" : { 
    "pakistan" : 188346000 
  } 
}
EOF

HTTP/1.1 Accepted
etag: "_ZZB_-9S--_"
keep-alive: timeout=300
location: /_db/_system/_api/document/products/69794
x-content-type-options: nosniff
content-type: application/json

shell> curl --header 'accept: application/json' --dump - http://localhost:8529/_api/document/products/69794

HTTP/1.1 OK
etag: "_ZZB_-9S--_"
keep-alive: timeout=300
x-content-type-options: nosniff
content-type: application/json

Show response body

Removes a document

removes a document

DELETE /_api/document/{document-handle}

Path Parameters

  • document-handle (required): Removes the document identified by document-handle.

Query Parameters

  • waitForSync (optional): Wait until deletion operation has been synced to disk.

  • returnOld (optional): Return additionally the complete previous revision of the changed document under the attribute old in the result.

  • silent (optional): If set to true, an empty object will be returned as response. No meta-data will be returned for the removed document. This option can be used to save some network traffic.

Header Parameters

  • If-Match (optional): You can conditionally remove a document based on a target revision id by using the if-match HTTP header.

If silent is not set to true, the body of the response contains a JSON object with the information about the handle and the revision. The attribute _id contains the known document-handle of the removed document, _key contains the key which uniquely identifies a document in a given collection, and the attribute _rev contains the document revision.

If the waitForSync parameter is not specified or set to false, then the collection’s default waitForSync behavior is applied. The waitForSync query parameter cannot be used to disable synchronization for collections that have a default waitForSync value of true.

If the query parameter returnOld is true, then the complete previous revision of the document is returned under the old attribute in the result.

Return codes

  • 200: is returned if the document was removed successfully and waitForSync was true.

  • 202: is returned if the document was removed successfully and waitForSync was false.

  • 404: is returned if the collection or the document was not found. The response body contains an error document in this case.

  • 412: is returned if a “If-Match” header or rev is given and the found document has a different version. The response will also contain the found document’s current revision in the _rev attribute. Additionally, the attributes _id and _key will be returned.

Examples

Using document handle:

shell> curl -X DELETE --header 'accept: application/json' --dump - http://localhost:8529/_api/document/products/69714

HTTP/1.1 OK
etag: "_ZZB_-4---A"
keep-alive: timeout=300
location: /_db/_system/_api/document/products/69714
x-content-type-options: nosniff
content-type: application/json

Show response body

Unknown document handle:

shell> curl -X DELETE --header 'accept: application/json' --dump - http://localhost:8529/_api/document/products/69758

HTTP/1.1 Not Found
keep-alive: timeout=300
x-content-type-options: nosniff
content-type: application/json

Show response body

Revision conflict:

shell> curl -X DELETE --header 'If-Match: "_ZZB_-46--C"' --header 'accept: application/json' --dump - http://localhost:8529/_api/document/products/69724

HTTP/1.1 Precondition Failed
etag: "_ZZB_-46--A"
keep-alive: timeout=300
x-content-type-options: nosniff
content-type: application/json

Show response body

Bulk Document Operations

ArangoDB supports working with document in bulk. Bulk operations affect a single collection. Using this API variant allows clients to amortize the overhead of single requests over an entire batch of documents. Bulk operations are not guaranteed to be executed serially, ArangoDB may execute the operations in parallel. This can translate into large performance improvements especially in a cluster deployment.

ArangoDB will continue to process the remaining operations should an error occur during the processing of one operation. Errors are returned inline in the response body as an error document (see below for more details). Additionally the X-Arango-Error-Codes header will contains a map of the error codes that occurred together with their multiplicities, like 1205:10,1210:17 which means that in 10 cases the error 1205 illegal document handle and in 17 cases the error 1210 unique constraint violated has happened.

Generally the bulk operations expect an input array and the result body will contain a JSON array of the same length.

Read multiple documents

reads a single document

PUT /_api/document/{collection-name}

Path Parameters

  • collection-name (required): The collection from which the documents are to be read.

Query Parameters

  • onlyget (required): This parameter is required to be true, otherwise a replace operation is executed

  • ignoreRevs (optional): Should the value be true (the default): If a search document contains a value for the _rev field, then the document is only returned if it has the same revision value. Otherwise a precondition failed error is returned.

Returns the documents identified by their _key in the body objects. The body of the request must contain a JSON array of either strings (the _key values to lookup) or search documents.

A search document must contain at least a value for the _key field. A value for _rev may be specified to verify whether the document has the same revision value, unless ignoreRevs is set to false.

Cluster only: The search document may contain
values for the collection’s pre-defined shard keys. Values for the shard keys are treated as hints to improve performance. Should the shard keys values be incorrect ArangoDB may answer with a not found error.

The returned array of documents contain three special attributes: _id containing the document handle, _key containing key which uniquely identifies a document in a given collection and _rev containing the revision.

Return codes

  • 200: is returned if no error happened

  • 400: is returned if the body does not contain a valid JSON representation of an array of documents. The response body contains an error document in this case.

  • 404: is returned if the collection was not found.

Examples

Reading multiple documents handle:

shell> curl -X PUT --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/document/products?onlyget=true <<EOF
["doc1", {"_key":"doc2"}]
EOF

HTTP/1.1 OK
keep-alive: timeout=300
x-content-type-options: nosniff
content-type: application/json

[ 
  { 
    "_key" : "doc1", 
    "_id" : "products/doc1", 
    "_rev" : "_ZZB__Ca--A", 
    "hello" : "world" 
  }, 
  { 
    "_key" : "doc2", 
    "_id" : "products/doc2", 
    "_rev" : "_ZZB__Ca--C", 
    "say" : "hi to mom" 
  } 
]

Create document

creates multiple documents

POST /_api/document/{collection-name}

Path Parameters

  • collection-name (required): The collection in which the documents are to be created.

Query Parameters

  • collection (optional): The name of the collection. This is only for backward compatibility. In ArangoDB versions < 3.0, the URL path was /_api/document and this query parameter was required. This combination still works, but the recommended way is to specify the collection in the URL path.

  • waitForSync (optional): Wait until document has been synced to disk.

  • returnNew (optional): Additionally return the complete new document under the attribute new in the result.

  • returnOld (optional): Additionally return the complete old document under the attribute old in the result. Only available if the overwrite option is used.

  • silent (optional): If set to true, an empty object will be returned as response. No meta-data will be returned for the created document. This option can be used to save some network traffic.

  • overwrite (optional): If set to true, the insert becomes a replace-insert. If a document with the same _key already exists the new document is not rejected with unique constraint violated but will replace the old document.

Request Body (json)

An array of documents to create.

Creates new documents from the documents given in the body, unless there is already a document with the _key given. If no _key is given, a new unique _key is generated automatically.

The result body will contain a JSON array of the same length as the input array, and each entry contains the result of the operation for the corresponding input. In case of an error the entry is a document with attributes error set to true and errorCode set to the error code that has happened.

Possibly given _id and _rev attributes in the body are always ignored, the URL part or the query parameter collection respectively counts.

If silent is not set to true, the body of the response contains an array of JSON objects with the following attributes:

  • _id contains the document handle of the newly created document
  • _key contains the document key
  • _rev contains the document revision

If the collection parameter waitForSync is false, then the call returns as soon as the documents have been accepted. It will not wait until the documents have been synced to disk.

Optionally, the query parameter waitForSync can be used to force synchronization of the document creation operation to disk even in case that the waitForSync flag had been disabled for the entire collection. Thus, the waitForSync query parameter can be used to force synchronization of just this 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 query parameter cannot be used to disable synchronization for collections that have a default waitForSync value of true.

If the query parameter returnNew is true, then, for each generated document, the complete new document is returned under the new attribute in the result.

Should an error have occurred with some of the documents the additional HTTP header X-Arango-Error-Codes is set, which contains a map of the error codes that occurred together with their multiplicities, as in: 1205:10,1210:17 which means that in 10 cases the error 1205 “illegal document handle” and in 17 cases the error 1210 “unique constraint violated” has happened.

Return codes

  • 201: is returned if waitForSync was true and operations were processed.

  • 202: is returned if waitForSync was false and operations were processed.

  • 400: is returned if the body does not contain a valid JSON representation of an array of documents. The response body contains an error document in this case.

  • 404: is returned if the collection specified by collection is unknown. The response body contains an error document in this case.

Examples

Insert multiple documents:

shell> curl -X POST --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/document/products <<EOF
[{"Hello":"Earth"}, {"Hello":"Venus"}, {"Hello":"Mars"}]
EOF

HTTP/1.1 Accepted
keep-alive: timeout=300
x-content-type-options: nosniff
content-type: application/json

[ 
  { 
    "_id" : "products/69841", 
    "_key" : "69841", 
    "_rev" : "_ZZB__-y--A" 
  }, 
  { 
    "_id" : "products/69842", 
    "_key" : "69842", 
    "_rev" : "_ZZB__-y--C" 
  }, 
  { 
    "_id" : "products/69843", 
    "_key" : "69843", 
    "_rev" : "_ZZB__-y--E" 
  } 
]

Use of returnNew:

shell> curl -X POST --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/document/products?returnNew=true <<EOF
[{"Hello":"Earth"}, {"Hello":"Venus"}, {"Hello":"Mars"}]
EOF

HTTP/1.1 Accepted
keep-alive: timeout=300
x-content-type-options: nosniff
content-type: application/json

[ 
  { 
    "_id" : "products/69852", 
    "_key" : "69852", 
    "_rev" : "_ZZB___C---", 
    "new" : { 
      "_key" : "69852", 
      "_id" : "products/69852", 
      "_rev" : "_ZZB___C---", 
      "Hello" : "Earth" 
    } 
  }, 
  { 
    "_id" : "products/69853", 
    "_key" : "69853", 
    "_rev" : "_ZZB___C--A", 
    "new" : { 
      "_key" : "69853", 
      "_id" : "products/69853", 
      "_rev" : "_ZZB___C--A", 
      "Hello" : "Venus" 
    } 
  }, 
  { 
    "_id" : "products/69854", 
    "_key" : "69854", 
    "_rev" : "_ZZB___C--C", 
    "new" : { 
      "_key" : "69854", 
      "_id" : "products/69854", 
      "_rev" : "_ZZB___C--C", 
      "Hello" : "Mars" 
    } 
  } 
]

Partially illegal documents:

shell> curl -X POST --header 'accept: application/json' --data-binary @- --dump - http://localhost:8529/_api/document/products <<EOF
[{ "_key": 111 }, {"_key":"abc"}]
EOF

HTTP/1.1 Accepted
keep-alive: timeout=300
x-arango-error-codes: {"1221":1}
x-content-type-options: nosniff
content-type: application/json

[ 
  { 
    "error" : true, 
    "errorNum" : 1221, 
    "errorMessage" : "illegal document key" 
  }, 
  { 
    "_id" : "products/abc", 
    "_key" : "abc", 
    "_rev" : "_ZZB__-K---" 
  } 
]

Replace documents

replaces multiple documents

PUT /_api/document/{collection}

Path Parameters

  • collection (required): This URL parameter is the name of the collection in which the documents are replaced.

Query Parameters

  • waitForSync (optional): Wait until the new documents have been synced to disk.

  • ignoreRevs (optional): By default, or if this is set to true, the _rev attributes in the given documents are ignored. If this is set to false, then any _rev attribute given in a body document is taken as a precondition. The document is only replaced if the current revision is the one specified.

  • returnOld (optional): Return additionally the complete previous revision of the changed documents under the attribute old in the result.

  • returnNew (optional): Return additionally the complete new documents under the attribute new in the result.

Request Body (json)

A JSON representation of an array of documents.

Replaces multiple documents in the specified collection with the ones in the body, the replaced documents are specified by the _key attributes in the body documents.

The value of the _key attribute as well as attributes used as sharding keys may not be changed.

If ignoreRevs is false and there is a _rev attribute in a document in the body and its value does not match the revision of the corresponding document in the database, the precondition is violated.

Cluster only: The replace documents may contain
values for the collection’s pre-defined shard keys. Values for the shard keys are treated as hints to improve performance. Should the shard keys values be incorrect ArangoDB may answer with a not found error.

Optionally, the query parameter waitForSync 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 query 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 query parameter cannot be used to disable synchronization for collections that have a default waitForSync value of true.

The body of the response contains a JSON array of the same length as the input array with the information about the handle and the revision of the replaced documents. In each entry, the attribute _id contains the known document-handle of each updated document, _key contains the key which uniquely identifies a document in a given collection, and the attribute _rev contains the new document revision. In case of an error or violated precondition, an error object with the attribute error set to true and the attribute errorCode set to the error code is built.

If the query parameter returnOld is true, then, for each generated document, the complete previous revision of the document is returned under the old attribute in the result.

If the query parameter returnNew is true, then, for each generated document, the complete new document is returned under the new attribute in the result.

Note that if any precondition is violated or an error occurred with some of the documents, the return code is still 201 or 202, but the additional HTTP header X-Arango-Error-Codes is set, which contains a map of the error codes that occurred together with their multiplicities, as in: 1200:17,1205:10 which means that in 17 cases the error 1200 “revision conflict” and in 10 cases the error 1205 “illegal document handle” has happened.

Return codes

  • 201: is returned if waitForSync was true and operations were processed.

  • 202: is returned if waitForSync was false and operations were processed.

  • 400: is returned if the body does not contain a valid JSON representation of an array of documents. The response body contains an error document in this case.

  • 404: is returned if the collection was not found.

Update documents

updates multiple documents

PATCH /_api/document/{collection}

Path Parameters

  • collection (required): This URL parameter is the name of the collection in which the documents are updated.

Query Parameters

  • keepNull (optional): If the intention is to delete existing attributes with the patch command, the URL query parameter keepNull can be used with a value of false. This will modify the behavior of the patch command to remove any attributes from the existing document that are contained in the patch document with an attribute value of null.

  • mergeObjects (optional): 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.

  • waitForSync (optional): Wait until the new documents have been synced to disk.

  • ignoreRevs (optional): By default, or if this is set to true, the _rev attributes in the given documents are ignored. If this is set to false, then any _rev attribute given in a body document is taken as a precondition. The document is only updated if the current revision is the one specified.

  • returnOld (optional): Return additionally the complete previous revision of the changed documents under the attribute old in the result.

  • returnNew (optional): Return additionally the complete new documents under the attribute new in the result.

Request Body (json)

A JSON representation of an array of document updates as objects.

Partially updates documents, the documents to update are specified by the _key attributes in the body objects. The body of the request must contain a JSON array of document updates with the attributes to patch (the patch documents). All attributes from the patch documents will be added to the existing documents if they do not yet exist, and overwritten in the existing documents if they do exist there.

The value of the _key attribute as well as attributes used as sharding keys may not be changed.

Setting an attribute value to null in the patch documents will cause a value of null to be saved for the attribute by default.

If ignoreRevs is false and there is a _rev attribute in a document in the body and its value does not match the revision of the corresponding document in the database, the precondition is violated.

Cluster only: The patch document may contain
values for the collection’s pre-defined shard keys. Values for the shard keys are treated as hints to improve performance. Should the shard keys values be incorrect ArangoDB may answer with a not found error

Optionally, the query parameter waitForSync 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 query 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 query parameter cannot be used to disable synchronization for collections that have a default waitForSync value of true.

The body of the response contains a JSON array of the same length as the input array with the information about the handle and the revision of the updated documents. In each entry, the attribute _id contains the known document-handle of each updated document, _key contains the key which uniquely identifies a document in a given collection, and the attribute _rev contains the new document revision. In case of an error or violated precondition, an error object with the attribute error set to true and the attribute errorCode set to the error code is built.

If the query parameter returnOld is true, then, for each generated document, the complete previous revision of the document is returned under the old attribute in the result.

If the query parameter returnNew is true, then, for each generated document, the complete new document is returned under the new attribute in the result.

Note that if any precondition is violated or an error occurred with some of the documents, the return code is still 201 or 202, but the additional HTTP header X-Arango-Error-Codes is set, which contains a map of the error codes that occurred together with their multiplicities, as in: 1200:17,1205:10 which means that in 17 cases the error 1200 “revision conflict” and in 10 cases the error 1205 “illegal document handle” has happened.

Return codes

  • 201: is returned if waitForSync was true and operations were processed.

  • 202: is returned if waitForSync was false and operations were processed.

  • 400: is returned if the body does not contain a valid JSON representation of an array of documents. The response body contains an error document in this case.

  • 404: is returned if the collection was not found.

Removes multiple documents

removes multiple document

DELETE /_api/document/{collection}

Path Parameters

  • collection (required): Collection from which documents are removed.

Query Parameters

  • waitForSync (optional): Wait until deletion operation has been synced to disk.

  • returnOld (optional): Return additionally the complete previous revision of the changed document under the attribute old in the result.

  • ignoreRevs (optional): If set to true, ignore any _rev attribute in the selectors. No revision check is performed.

Request Body (json)

A JSON array of strings or documents.

The body of the request is an array consisting of selectors for documents. A selector can either be a string with a key or a string with a document handle or an object with a _key attribute. This API call removes all specified documents from collection. If the selector is an object and has a _rev attribute, it is a precondition that the actual revision of the removed document in the collection is the specified one.

The body of the response is an array of the same length as the input array. For each input selector, the output contains a JSON object with the information about the outcome of the operation. If no error occurred, an object is built in which the attribute _id contains the known document-handle of the removed document, _key contains the key which uniquely identifies a document in a given collection, and the attribute _rev contains the document revision. In case of an error, an object with the attribute error set to true and errorCode set to the error code is built.

If the waitForSync parameter is not specified or set to false, then the collection’s default waitForSync behavior is applied. The waitForSync query parameter cannot be used to disable synchronization for collections that have a default waitForSync value of true.

If the query parameter returnOld is true, then the complete previous revision of the document is returned under the old attribute in the result.

Note that if any precondition is violated or an error occurred with some of the documents, the return code is still 200 or 202, but the additional HTTP header X-Arango-Error-Codes is set, which contains a map of the error codes that occurred together with their multiplicities, as in: 1200:17,1205:10 which means that in 17 cases the error 1200 “revision conflict” and in 10 cases the error 1205 “illegal document handle” has happened.

Return codes

  • 200: is returned if waitForSync was true.

  • 202: is returned if waitForSync was false.

  • 404: is returned if the collection was not found. The response body contains an error document in this case.

Examples

Using document handle:

shell> curl -X DELETE --header 'accept: application/json' --dump - http://localhost:8529/_api/document/products/69748

HTTP/1.1 OK
etag: "_ZZB_-5i---"
keep-alive: timeout=300
location: /_db/_system/_api/document/products/69748
x-content-type-options: nosniff
content-type: application/json

Show response body

Unknown document handle:

shell> curl -X DELETE --header 'accept: application/json' --dump - http://localhost:8529/_api/document/products/69769

HTTP/1.1 Not Found
keep-alive: timeout=300
x-content-type-options: nosniff
content-type: application/json

Show response body

Revision conflict:

shell> curl -X DELETE --header 'If-Match: "_ZZB_-5O---"' --header 'accept: application/json' --dump - http://localhost:8529/_api/document/products/69736

HTTP/1.1 Precondition Failed
etag: "_ZZB_-5K--A"
keep-alive: timeout=300
x-content-type-options: nosniff
content-type: application/json

Show response body