ArangoDB v2.8 reached End of Life (EOL) and is no longer supported.
This documentation is outdated. Please see the most recent version here: Try latest
Working with Documents using REST
Read document
reads a single document
GET /_api/document/{collection-name}/{document-key}
Path Parameters
- collection-name (required): The name of the collection.
-
document-key (required): The key 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. As an alternative you can supply the etag in an attribute rev in the URL.
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 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
Use a document handle:
shell> curl --dump - http://localhost:8529/_api/document/products/729434241
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
etag: "729434241"
{
"hello" : "world",
"_id" : "products/729434241",
"_rev" : "729434241",
"_key" : "729434241"
}
shell> curl --dump - http://localhost:8529/_api/document/products/729434241
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
etag: "729434241"
Use a document handle and an etag:
shell> curl --header 'If-None-Match: "733104257"' --dump - http://localhost:8529/_api/document/products/733104257
Unknown document handle:
shell> curl --dump - http://localhost:8529/_api/document/products/unknownhandle
HTTP/1.1 404 Not Found
content-type: application/json; charset=utf-8
{
"error" : true,
"errorMessage" : "collection 'products' not found",
"code" : 404,
"errorNum" : 1203
}
shell> curl --dump - http://localhost:8529/_api/document/products/unknownhandle
HTTP/1.1 404 Not Found
content-type: application/json; charset=utf-8
Create document
creates a document
POST /_api/document
Query Parameters
- collection (required): The collection name.
- createCollection (optional): If this parameter has a value of true or yes, then the collection is
created if it does not yet exist. Other values will be ignored so the
collection must be present for the operation to succeed.
Note: this flag is not supported in a cluster. Using it will result in an error. - waitForSync (optional): Wait until document has been synced to disk.
Request Body (json)
A JSON representation of the document.
Creates a new document in the collection named collection. A JSON
representation of the document must be passed as the body of the POST
request.
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.
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 document has 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.
Return codes-
201: is returned if the document was created successfully and waitForSync was true.
-
202: is returned if the document was created 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 specified by collection is unknown. 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 --data-binary @- --dump - http://localhost:8529/_api/document?collection=products <<EOF
{ "Hello": "World" }
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
etag: "727861377"
location: /_db/_system/_api/document/products/727861377
{
"error" : false,
"_id" : "products/727861377",
"_rev" : "727861377",
"_key" : "727861377"
}
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/document?collection=products <<EOF
{ "Hello": "World" }
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
etag: "727861377"
location: /_db/_system/_api/document/products/727861377
Create a document in a collection named products with a collection-level
waitForSync value of false.
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/document?collection=products <<EOF
{ "Hello": "World" }
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: "727337089"
location: /_db/_system/_api/document/products/727337089
{
"error" : false,
"_id" : "products/727337089",
"_rev" : "727337089",
"_key" : "727337089"
}
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/document?collection=products <<EOF
{ "Hello": "World" }
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: "727337089"
location: /_db/_system/_api/document/products/727337089
Create a document in a collection with a collection-level waitForSync
value of false, but using the waitForSync query parameter.
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/document?collection=products&waitForSync=true <<EOF
{ "Hello": "World" }
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
etag: "728909953"
location: /_db/_system/_api/document/products/728909953
{
"error" : false,
"_id" : "products/728909953",
"_rev" : "728909953",
"_key" : "728909953"
}
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/document?collection=products&waitForSync=true <<EOF
{ "Hello": "World" }
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
etag: "728909953"
location: /_db/_system/_api/document/products/728909953
Create a document in a new, named collection
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/document?collection=products&createCollection=true <<EOF
{ "Hello": "World" }
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: "728385665"
location: /_db/_system/_api/document/products/728385665
{
"error" : false,
"_id" : "products/728385665",
"_rev" : "728385665",
"_key" : "728385665"
}
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/document?collection=products&createCollection=true <<EOF
{ "Hello": "World" }
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: "728385665"
location: /_db/_system/_api/document/products/728385665
Unknown collection name
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/document?collection=products <<EOF
{ "Hello": "World" }
EOF
HTTP/1.1 404 Not Found
content-type: application/json; charset=utf-8
{
"error" : true,
"errorMessage" : "collection 'products' not found",
"code" : 404,
"errorNum" : 1203
}
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/document?collection=products <<EOF
{ "Hello": "World" }
EOF
HTTP/1.1 404 Not Found
content-type: application/json; charset=utf-8
Illegal document
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/document?collection=products <<EOF
{ 1: "World" }
EOF
HTTP/1.1 400 Bad Request
content-type: application/json; charset=utf-8
{
"error" : true,
"errorMessage" : "expecting attribute name",
"code" : 400,
"errorNum" : 600
}
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/document?collection=products <<EOF
{ 1: "World" }
EOF
HTTP/1.1 400 Bad Request
content-type: application/json; charset=utf-8
Replace document
replaces a document
PUT /_api/document/{collection-name}/{document-key}
Path Parameters
- collection-name (required): The name of the collection.
-
document-key (required): The key of the document.
Query Parameters - waitForSync (optional): Wait until document has been synced to disk.
- rev (optional): You can conditionally replace a document based on a target revision id by
using the rev query parameter.
-
policy (optional): To control the update behavior in case there is a revision mismatch, you can use the policy parameter (see below).
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 the new document.
Completely updates (i.e. replaces) the document identified by document-handle.
If the document exists and can be updated, then a HTTP 201 is returned
and the “ETag” header field contains the new revision of the document.
If the new document passed in the body of the request contains the
document-handle in the attribute _id and the revision
in _rev,
these attributes will be ignored. Only the URI and the “ETag” header are
relevant in order to avoid confusion when using proxies.
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 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 document does not exist, then a HTTP 404 is returned and the
body of the response contains an error document.
There are two ways for specifying the targeted document revision id for
conditional replacements (i.e. replacements that will only be executed if
the revision id found in the database matches the document revision id specified
in the request):
- specifying the target revision in the rev URL query parameter
-
specifying the target revision in the if-match HTTP header
Specifying a target revision is optional, however, if done, only one of the described mechanisms must be used (either the rev query parameter or the if-match HTTP header). Regardless which mechanism is used, the parameter needs to contain the target document revision id as returned in the _rev attribute of a document or by an HTTP etag header.
For example, to conditionally replace a document based on a specific revision id, you can use the following request:
PUT /_api/document/collection-name/document-key?rev=etag
If a target revision id is provided in the request (e.g. via the etag value in the rev URL query parameter above), ArangoDB will check that the revision id of the document found in the database is equal to the target revision id provided in the request. If there is a mismatch between the revision id, then by default a HTTP 412 conflict is returned and no replacement is performed.
The conditional update behavior can be overridden with the policy URL query parameter:
PUT /_api/document/collection-name/document-key?policy=policy
If policy is set to error, then the behavior is as before: replacements will fail if the revision id found in the database does not match the target revision id specified in the request.
If policy is set to last, then the replacement will succeed, even if the revision id found in the database does not match the target revision id specified in the request. You can use the last policy to force replacements.
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 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 a document handle
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/document/products/733694081 <<EOF
{"Hello": "you"}
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: "734021761"
location: /_db/_system/_api/document/products/733694081
{
"error" : false,
"_id" : "products/733694081",
"_rev" : "734021761",
"_key" : "733694081"
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/document/products/733694081 <<EOF
{"Hello": "you"}
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: "734021761"
location: /_db/_system/_api/document/products/733694081
Unknown document handle
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/document/products/737888385 <<EOF
{}
EOF
HTTP/1.1 404 Not Found
content-type: application/json; charset=utf-8
{
"error" : true,
"errorMessage" : "document not found",
"code" : 404,
"errorNum" : 1202
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/document/products/737888385 <<EOF
{}
EOF
HTTP/1.1 404 Not Found
content-type: application/json; charset=utf-8
Produce a revision conflict
shell> curl -X PUT --header 'If-Match: "734873729"' --data-binary @- --dump - http://localhost:8529/_api/document/products/734546049 <<EOF
{"other":"content"}
EOF
HTTP/1.1 412 Precondition Failed
content-type: application/json; charset=utf-8
etag: "734546049"
{
"error" : true,
"code" : 412,
"errorNum" : 1200,
"errorMessage" : "precondition failed",
"_id" : "products/734546049",
"_rev" : "734546049",
"_key" : "734546049"
}
shell> curl -X PUT --header 'If-Match: "734873729"' --data-binary @- --dump - http://localhost:8529/_api/document/products/734546049 <<EOF
{"other":"content"}
EOF
HTTP/1.1 412 Precondition Failed
content-type: application/json; charset=utf-8
etag: "734546049"
Last write wins
shell> curl -X PUT --header 'If-Match: "735987841"' --data-binary @- --dump - http://localhost:8529/_api/document/products/735660161?policy=last <<EOF
{}
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: "736249985"
location: /_db/_system/_api/document/products/735660161
{
"error" : false,
"_id" : "products/735660161",
"_rev" : "736249985",
"_key" : "735660161"
}
shell> curl -X PUT --header 'If-Match: "735987841"' --data-binary @- --dump - http://localhost:8529/_api/document/products/735660161?policy=last <<EOF
{}
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: "736249985"
location: /_db/_system/_api/document/products/735660161
Alternative to header fields
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/document/products/736774273?rev=737101953 <<EOF
{"other":"content"}
EOF
HTTP/1.1 412 Precondition Failed
content-type: application/json; charset=utf-8
etag: "736774273"
{
"error" : true,
"code" : 412,
"errorNum" : 1200,
"errorMessage" : "precondition failed",
"_id" : "products/736774273",
"_rev" : "736774273",
"_key" : "736774273"
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/document/products/736774273?rev=737101953 <<EOF
{"other":"content"}
EOF
HTTP/1.1 412 Precondition Failed
content-type: application/json; charset=utf-8
etag: "736774273"
Patch document
updates a document
PATCH /_api/document/{collection-name}/{document-key}
Path Parameters
- collection-name (required): The name of the collection.
-
document-key (required): The key of the document.
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.
- rev (optional): You can conditionally patch a document based on a target revision id by
using the rev query parameter.
-
policy (optional): To control the update behavior in case there is a revision mismatch, you can use the policy parameter.
Header Parameters - If-Match (optional): You can conditionally patch a document based on a target revision id by
using the if-match HTTP header.
Request Body (json)
A JSON representation of the document update.
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.
Setting an attribute value to null in the patch document will cause a
value of null be saved for the attribute by default.
Optionally, the query parameter waitForSync can be used to force
synchronization of the document update 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 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 document does not exist, then a HTTP 404 is returned and the
body of the response contains an error document.
You can conditionally update a document based on a target revision id by
using either the rev query parameter or the if-match HTTP header.
To control the update behavior in case there is a revision mismatch, you
can use the policy parameter. This is the same as when replacing
documents (see replacing documents for details).
Return codes
-
201: is returned if the document was created successfully and waitForSync was true.
-
202: is returned if the document was created 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 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
patches an existing document with new content.
shell> curl -X PATCH --data-binary @- --dump - http://localhost:8529/_api/document/products/723536001 <<EOF
{
"hello" : "world"
}
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: "723863681"
location: /_db/_system/_api/document/products/723536001
{
"error" : false,
"_id" : "products/723536001",
"_rev" : "723863681",
"_key" : "723536001"
}
shell> curl -X PATCH --data-binary @- --dump - http://localhost:8529/_api/document/products/723536001 <<EOF
{
"numbers" : {
"one" : 1,
"two" : 2,
"three" : 3,
"empty" : null
}
}
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: "724453505"
location: /_db/_system/_api/document/products/723536001
{
"error" : false,
"_id" : "products/723536001",
"_rev" : "724453505",
"_key" : "723536001"
}
shell> curl --dump - http://localhost:8529/_api/document/products/723536001
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
etag: "724453505"
{
"one" : "world",
"hello" : "world",
"numbers" : {
"empty" : null,
"one" : 1,
"two" : 2,
"three" : 3
},
"_id" : "products/723536001",
"_rev" : "724453505",
"_key" : "723536001"
}
shell> curl -X PATCH --data-binary @- --dump - http://localhost:8529/_api/document/products/723536001?keepNull=false <<EOF
{
"hello" : null,
"numbers" : {
"four" : 4
}
}
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: "724912257"
location: /_db/_system/_api/document/products/723536001
{
"error" : false,
"_id" : "products/723536001",
"_rev" : "724912257",
"_key" : "723536001"
}
shell> curl --dump - http://localhost:8529/_api/document/products/723536001
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
etag: "724912257"
{
"one" : "world",
"numbers" : {
"empty" : null,
"one" : 1,
"two" : 2,
"three" : 3,
"four" : 4
},
"_id" : "products/723536001",
"_rev" : "724912257",
"_key" : "723536001"
}
shell> curl -X PATCH --data-binary @- --dump - http://localhost:8529/_api/document/products/723536001 <<EOF
{
"hello" : "world"
}
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: "723863681"
location: /_db/_system/_api/document/products/723536001
Merging attributes of an object using mergeObjects
:
shell> curl --dump - http://localhost:8529/_api/document/products/725764225
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
etag: "725764225"
{
"inhabitants" : {
"china" : 1366980000,
"india" : 1263590000,
"usa" : 319220000
},
"_id" : "products/725764225",
"_rev" : "725764225",
"_key" : "725764225"
}
shell> curl -X PATCH --data-binary @- --dump - http://localhost:8529/_api/document/products/725764225?mergeObjects=true <<EOF
{
"inhabitants" : {
"indonesia" : 252164800,
"brazil" : 203553000
}
}
EOF
shell> curl --dump - http://localhost:8529/_api/document/products/725764225
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
etag: "726288513"
{
"inhabitants" : {
"china" : 1366980000,
"india" : 1263590000,
"usa" : 319220000,
"indonesia" : 252164800,
"brazil" : 203553000
},
"_id" : "products/725764225",
"_rev" : "726288513",
"_key" : "725764225"
}
shell> curl -X PATCH --data-binary @- --dump - http://localhost:8529/_api/document/products/725764225?mergeObjects=false <<EOF
{
"inhabitants" : {
"pakistan" : 188346000
}
}
EOF
HTTP/1.1 202 Accepted
content-type: application/json; charset=utf-8
etag: "726747265"
location: /_db/_system/_api/document/products/725764225
{
"error" : false,
"_id" : "products/725764225",
"_rev" : "726747265",
"_key" : "725764225"
}
shell> curl --dump - http://localhost:8529/_api/document/products/725764225
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
etag: "726747265"
{
"inhabitants" : {
"pakistan" : 188346000
},
"_id" : "products/725764225",
"_rev" : "726747265",
"_key" : "725764225"
}
shell> curl --dump - http://localhost:8529/_api/document/products/725764225
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
etag: "725764225"
Removes a document
removes a document
DELETE /_api/document/{collection-name}/{document-key}
Path Parameters
- collection-name (required): The name of the collection.
-
document-key (required): The key of the document.
Query Parameters - rev (optional): You can conditionally remove a document based on a target revision id by
using the rev query parameter.
- policy (optional): To control the update behavior in case there is a revision mismatch, you
can use the policy parameter. This is the same as when replacing
documents (see replacing documents for more details).
-
waitForSync (optional): Wait until deletion operation has been synced to disk.
Header Parameters -
If-Match (optional): You can conditionally remove a document based on a target revision id by using the if-match HTTP header.
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 new 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.
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 --dump - http://localhost:8529/_api/document/products/720980097
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"error" : false,
"_id" : "products/720980097",
"_rev" : "720980097",
"_key" : "720980097"
}
shell> curl -X DELETE --dump - http://localhost:8529/_api/document/products/720980097
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
Unknown document handle:
shell> curl -X DELETE --dump - http://localhost:8529/_api/document/products/722684033
HTTP/1.1 404 Not Found
content-type: application/json; charset=utf-8
{
"error" : true,
"errorMessage" : "document not found",
"code" : 404,
"errorNum" : 1202
}
shell> curl -X DELETE --dump - http://localhost:8529/_api/document/products/722684033
HTTP/1.1 404 Not Found
content-type: application/json; charset=utf-8
Revision conflict:
shell> curl -X DELETE --header 'If-Match: "722028673"' --dump - http://localhost:8529/_api/document/products/721700993
HTTP/1.1 412 Precondition Failed
content-type: application/json; charset=utf-8
etag: "721700993"
{
"error" : true,
"code" : 412,
"errorNum" : 1200,
"errorMessage" : "precondition failed",
"_id" : "products/721700993",
"_rev" : "721700993",
"_key" : "721700993"
}
shell> curl -X DELETE --header 'If-Match: "722028673"' --dump - http://localhost:8529/_api/document/products/721700993
HTTP/1.1 412 Precondition Failed
content-type: application/json; charset=utf-8
etag: "721700993"
Read document header
reads a single document head
HEAD /_api/document/{collection-name}/{document-key}
Path Parameters
- collection-name (required): The name of the collection.
-
document-key (required): The key of the document.
Query Parameters -
rev (optional): You can conditionally fetch a document based on a target revision id by using the rev query parameter.
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 different 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): You can conditionally fetch a document based on a target revision id by using the if-match HTTP header.
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 same version ///*
-
404: is returned if the document or collection was not found
- 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 etag header.
Examples
shell> curl -X HEAD --dump - http://localhost:8529/_api/document/products/732514433
Read all documents
reads all documents from collection
GET /_api/document
Query Parameters
- collection (required): The name of the collection.
- type (optional): The type of the result. The following values are allowed:
- id: returns an array of document ids (_id attributes)
- key: returns an array of document keys (_key attributes)
-
path: returns an array of document URI paths. This is the default.
Returns an array of all keys, ids, or URI paths for all documents in the collection identified by collection. The type of the result array is determined by the type attribute.
Note that the results have no defined order and thus the order should not be relied on.
Return codes-
200: All went good.
-
404: The collection does not exist.
-
Examples
Return all document paths
shell> curl --dump - http://localhost:8529/_api/document/?collection=products
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"documents" : [
"/_db/_system/_api/document/products/731924609",
"/_db/_system/_api/document/products/731269249",
"/_db/_system/_api/document/products/731596929"
]
}
shell> curl --dump - http://localhost:8529/_api/document/?collection=products
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
Return all document keys
shell> curl --dump - http://localhost:8529/_api/document/?collection=products&type=key
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"documents" : [
"730679425",
"730351745",
"730024065"
]
}
shell> curl --dump - http://localhost:8529/_api/document/?collection=products&type=key
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
Collection does not exist
shell> curl --dump - http://localhost:8529/_api/document/?collection=doesnotexist
HTTP/1.1 404 Not Found
content-type: application/json; charset=utf-8
{
"error" : true,
"errorMessage" : "collection 'doesnotexist' not found",
"code" : 404,
"errorNum" : 1203
}
shell> curl --dump - http://localhost:8529/_api/document/?collection=doesnotexist
HTTP/1.1 404 Not Found
content-type: application/json; charset=utf-8