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
HTTP Interface for Simple Queries
Simple Queries
This is an introduction to ArangoDB’s HTTP interface for simple queries.
Simple queries can be used if the query condition is straight forward simple, i.e., a document reference, all documents, a query-by-example, or a simple geo query. In a simple query you can specify exactly one collection and one condition. The result can then be sorted and can be split into pages.
Working with Simples Queries using HTTP
To limit the amount of results to be transferred in one batch, simple queries support a batchSize parameter that can optionally be used to tell the server to limit the number of results to be transferred in one batch to a certain value. If the query has more results than were transferred in one go, more results are waiting on the server so they can be fetched subsequently. If no value for the batchSize parameter is specified, the server will use a reasonable default value.
If the server has more documents than should be returned in a single batch, the server will set the hasMore attribute in the result. It will also return the id of the server-side cursor in the id attribute in the result. This id can be used with the cursor API to fetch any outstanding results from the server and dispose the server-side cursor afterwards.
Return all documents
returns all documents of a collection
PUT /_api/simple/all
Request Body (string)
Contains the query.
Returns all documents of a collections. The call expects a JSON object
as body with the following attributes:
- collection: The name of the collection to query.
- skip: The number of documents to skip in the query (optional).
-
limit: The maximal amount of documents to return. The skip is applied before the limit restriction. (optional)
Returns a cursor containing the result, see Http Cursor for details.
Return codes-
201: is returned if the query was executed successfully.
-
400: is returned if the body does not contain a valid JSON representation of a query. 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
Limit the amount of documents using limit
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/all <<EOF
{ "collection": "products", "skip": 2, "limit" : 2 }
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
{
"result" : [
{
"Hello3" : "World3",
"_id" : "products/797198465",
"_rev" : "797198465",
"_key" : "797198465"
},
{
"Hello4" : "World4",
"_id" : "products/797526145",
"_rev" : "797526145",
"_key" : "797526145"
}
],
"hasMore" : false,
"count" : 2,
"cached" : false,
"extra" : {
"stats" : {
"writesExecuted" : 0,
"writesIgnored" : 0,
"scannedFull" : 5,
"scannedIndex" : 0,
"filtered" : 0,
"executionTime" : 0.00010895729064941406
},
"warnings" : [ ]
},
"error" : false,
"code" : 201
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/all <<EOF
{ "collection": "products", "skip": 2, "limit" : 2 }
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
Using a batchSize value
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/all <<EOF
{ "collection": "products", "batchSize" : 3 }
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
{
"result" : [
{
"Hello2" : "World2",
"_id" : "products/794904705",
"_rev" : "794904705",
"_key" : "794904705"
},
{
"Hello5" : "World5",
"_id" : "products/795887745",
"_rev" : "795887745",
"_key" : "795887745"
},
{
"Hello1" : "World1",
"_id" : "products/794577025",
"_rev" : "794577025",
"_key" : "794577025"
}
],
"hasMore" : true,
"id" : "796084353",
"count" : 5,
"extra" : {
"stats" : {
"writesExecuted" : 0,
"writesIgnored" : 0,
"scannedFull" : 5,
"scannedIndex" : 0,
"filtered" : 0,
"executionTime" : 0.00010895729064941406
},
"warnings" : [ ]
},
"cached" : false,
"error" : false,
"code" : 201
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/all <<EOF
{ "collection": "products", "batchSize" : 3 }
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
Simple query by-example
returns all documents of a collection matching a given example
PUT /_api/simple/by-example
A JSON object with these properties is required:
-
collection: The name of the collection to query.
-
example: The example document.
-
skip: The number of documents to skip in the query (optional).
-
limit: The maximal amount of documents to return. The skip is applied before the limit restriction. (optional)
This will find all documents matching a given example.
Returns a cursor containing the result, see Http Cursor for details.
Return codes
-
201: is returned if the query was executed successfully.
-
400: is returned if the body does not contain a valid JSON representation of a query. 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
Matching an attribute
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/by-example <<EOF
{
"collection" : "products",
"example" : {
"i" : 1
}
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
{
"result" : [
{
"_id" : "products/800606337",
"_key" : "800606337",
"_rev" : "800606337",
"i" : 1,
"a" : {
"k" : 1,
"j" : 1
}
},
{
"_id" : "products/801392769",
"_key" : "801392769",
"_rev" : "801392769",
"i" : 1,
"a" : {
"k" : 2,
"j" : 2
}
},
{
"_id" : "products/801196161",
"_key" : "801196161",
"_rev" : "801196161",
"i" : 1
},
{
"_id" : "products/800934017",
"_key" : "800934017",
"_rev" : "800934017",
"i" : 1,
"a" : {
"j" : 1
}
}
],
"hasMore" : false,
"count" : 4,
"error" : false,
"code" : 201
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/by-example <<EOF
{
"collection" : "products",
"example" : {
"i" : 1
}
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
Matching an attribute which is a sub-document
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/by-example <<EOF
{
"collection" : "products",
"example" : {
"a.j" : 1
}
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
{
"result" : [
{
"_id" : "products/802900097",
"_key" : "802900097",
"_rev" : "802900097",
"i" : 1,
"a" : {
"j" : 1
}
},
{
"_id" : "products/802572417",
"_key" : "802572417",
"_rev" : "802572417",
"i" : 1,
"a" : {
"k" : 1,
"j" : 1
}
}
],
"hasMore" : false,
"count" : 2,
"error" : false,
"code" : 201
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/by-example <<EOF
{
"collection" : "products",
"example" : {
"a.j" : 1
}
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
Matching an attribute within a sub-document
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/by-example <<EOF
{
"collection" : "products",
"example" : {
"a" : {
"j" : 1
}
}
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
{
"result" : [
{
"_id" : "products/804866177",
"_key" : "804866177",
"_rev" : "804866177",
"i" : 1,
"a" : {
"j" : 1
}
}
],
"hasMore" : false,
"count" : 1,
"error" : false,
"code" : 201
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/by-example <<EOF
{
"collection" : "products",
"example" : {
"a" : {
"j" : 1
}
}
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
Find documents matching an example
returns one document of a collection matching a given example
PUT /_api/simple/first-example
A JSON object with these properties is required:
-
collection: The name of the collection to query.
-
example: The example document.
This will return the first document matching a given example.
Returns a result containing the document or HTTP 404 if no
document matched the example.
If more than one document in the collection matches the specified example, only
one of these documents will be returned, and it is undefined which of the matching
documents is returned.
Return codes
-
200: is returned when the query was successfully executed.
-
400: is returned if the body does not contain a valid JSON representation of a query. 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
If a matching document was found
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/first-example <<EOF
{
"collection" : "products",
"example" : {
"i" : 1
}
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"document" : {
"_id" : "products/808732801",
"_key" : "808732801",
"_rev" : "808732801",
"i" : 1
},
"error" : false,
"code" : 200
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/first-example <<EOF
{
"collection" : "products",
"example" : {
"i" : 1
}
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
If no document was found
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/first-example <<EOF
{
"collection" : "products",
"example" : {
"l" : 1
}
}
EOF
HTTP/1.1 404 Not Found
content-type: application/json; charset=utf-8
{
"error" : true,
"code" : 404,
"errorNum" : 404,
"errorMessage" : "no match"
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/first-example <<EOF
{
"collection" : "products",
"example" : {
"l" : 1
}
}
EOF
HTTP/1.1 404 Not Found
content-type: application/json; charset=utf-8
Find documents by their keys
fetches multiple documents by their keys
PUT /_api/simple/lookup-by-keys
A JSON object with these properties is required:
-
collection: The name of the collection to look in for the documents
-
keys: array with the _keys of documents to remove.
Looks up the documents in the specified collection using the array of keys
provided. All documents for which a matching key was specified in the keys
array and that exist in the collection will be returned.
Keys for which no document can be found in the underlying collection are ignored,
and no exception will be thrown for them.
The body of the response contains a JSON object with a documents attribute. The
documents attribute is an array containing the matching documents. The order in
which matching documents are present in the result array is unspecified.
Return codes
-
200: is returned if the operation was carried out successfully.
-
404: is returned if the collection was not found. The response body contains an error document in this case.
-
405: is returned if the operation was called with a different HTTP METHOD than PUT.
Examples
Looking up existing documents
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/lookup-by-keys <<EOF
{
"keys" : [
"test0",
"test1",
"test2",
"test3",
"test4",
"test5",
"test6",
"test7",
"test8",
"test9"
],
"collection" : "test"
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"documents" : [
{
"value" : 0,
"_id" : "test/test0",
"_rev" : "817907841",
"_key" : "test0"
},
{
"value" : 1,
"_id" : "test/test1",
"_rev" : "818104449",
"_key" : "test1"
},
{
"value" : 2,
"_id" : "test/test2",
"_rev" : "818301057",
"_key" : "test2"
},
{
"value" : 3,
"_id" : "test/test3",
"_rev" : "818497665",
"_key" : "test3"
},
{
"value" : 4,
"_id" : "test/test4",
"_rev" : "818694273",
"_key" : "test4"
},
{
"value" : 5,
"_id" : "test/test5",
"_rev" : "818890881",
"_key" : "test5"
},
{
"value" : 6,
"_id" : "test/test6",
"_rev" : "819087489",
"_key" : "test6"
},
{
"value" : 7,
"_id" : "test/test7",
"_rev" : "819284097",
"_key" : "test7"
},
{
"value" : 8,
"_id" : "test/test8",
"_rev" : "819480705",
"_key" : "test8"
},
{
"value" : 9,
"_id" : "test/test9",
"_rev" : "819677313",
"_key" : "test9"
}
],
"error" : false,
"code" : 200
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/lookup-by-keys <<EOF
{
"keys" : [
"test0",
"test1",
"test2",
"test3",
"test4",
"test5",
"test6",
"test7",
"test8",
"test9"
],
"collection" : "test"
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
Looking up non-existing documents
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/lookup-by-keys <<EOF
{
"keys" : [
"foo",
"bar",
"baz"
],
"collection" : "test"
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"documents" : [ ],
"error" : false,
"code" : 200
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/lookup-by-keys <<EOF
{
"keys" : [
"foo",
"bar",
"baz"
],
"collection" : "test"
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
Return a random document
returns a random document from a collection
PUT /_api/simple/any
A JSON object with these properties is required:
- collection: The identifier or name of the collection to query.
Returns a JSON object with the document stored in the attribute document if the collection contains at least one document. If the collection is empty, the document attrbute contains null.
Returns a random document from a collection. The call expects a JSON object
as body with the following attributes:
Return codes
-
200: is returned if the query was executed successfully.
-
400: is returned if the body does not contain a valid JSON representation of a query. 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
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/any <<EOF
{
"collection" : "products"
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"document" : {
"_id" : "products/799426689",
"_key" : "799426689",
"_rev" : "799426689",
"Hello4" : "World4"
},
"error" : false,
"code" : 200
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/any <<EOF
{
"collection" : "products"
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
Remove documents by their keys
removes multiple documents by their keys
PUT /_api/simple/remove-by-keys
A JSON object with these properties is required:
-
collection: The name of the collection to look in for the documents to remove
-
keys: array with the _keys of documents to remove.
-
options: a json object which can contains following attributes:
- waitForSync: if set to true, then all removal operations will
instantly be synchronized to disk. If this is not specified, then the
collection’s default sync behavior will be applied.
Looks up the documents in the specified collection using the array of keys provided, and removes all documents from the collection whose keys are contained in the keys array. Keys for which no document can be found in the underlying collection are ignored, and no exception will be thrown for them.
The body of the response contains a JSON object with information how many documents were removed (and how many were not). The removed attribute will contain the number of actually removed documents. The ignored attribute will contain the number of keys in the request for which no matching document could be found.
Return codes
- waitForSync: if set to true, then all removal operations will
instantly be synchronized to disk. If this is not specified, then the
collection’s default sync behavior will be applied.
-
200: is returned if the operation was carried out successfully. The number of removed documents may still be 0 in this case if none of the specified document keys were found in the collection.
-
404: is returned if the collection was not found. The response body contains an error document in this case.
-
405: is returned if the operation was called with a different HTTP METHOD than PUT.
Examples
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/remove-by-keys <<EOF
{
"keys" : [
"test0",
"test1",
"test2",
"test3",
"test4",
"test5",
"test6",
"test7",
"test8",
"test9"
],
"collection" : "test"
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"removed" : 10,
"ignored" : 0,
"error" : false,
"code" : 200
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/remove-by-keys <<EOF
{
"keys" : [
"test0",
"test1",
"test2",
"test3",
"test4",
"test5",
"test6",
"test7",
"test8",
"test9"
],
"collection" : "test"
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/remove-by-keys <<EOF
{
"keys" : [
"foo",
"bar",
"baz"
],
"collection" : "test"
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"removed" : 0,
"ignored" : 3,
"error" : false,
"code" : 200
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/remove-by-keys <<EOF
{
"keys" : [
"foo",
"bar",
"baz"
],
"collection" : "test"
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
Remove documents by example
removes all documents of a collection that match an example
PUT /_api/simple/remove-by-example
A JSON object with these properties is required:
-
collection: The name of the collection to remove from.
-
example: An example document that all collection documents are compared against.
-
options: a json object which can contains following attributes:
- waitForSync: if set to true, then all removal operations will
instantly be synchronized to disk. If this is not specified, then the
collection’s default sync behavior will be applied.
- limit: an optional value that determines how many documents to
delete at most. If limit is specified but is less than the number
of documents in the collection, it is undefined which of the documents
will be deleted.
This will find all documents in the collection that match the specified example object.
Note: the limit attribute is not supported on sharded collections. Using it will result in an error.
Returns the number of documents that were deleted.
Return codes
- waitForSync: if set to true, then all removal operations will
instantly be synchronized to disk. If this is not specified, then the
collection’s default sync behavior will be applied.
-
200: is returned if the query was executed successfully.
-
400: is returned if the body does not contain a valid JSON representation of a query. 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
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/remove-by-example <<EOF
{
"collection" : "products",
"example" : {
"a" : {
"j" : 1
}
}
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"deleted" : 1,
"error" : false,
"code" : 200
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/remove-by-example <<EOF
{
"collection" : "products",
"example" : {
"a" : {
"j" : 1
}
}
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
Using Parameter: waitForSync and limit
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/remove-by-example <<EOF
{
"collection" : "products",
"example" : {
"a" : {
"j" : 1
}
},
"waitForSync" : true,
"limit" : 2
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"deleted" : 1,
"error" : false,
"code" : 200
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/remove-by-example <<EOF
{
"collection" : "products",
"example" : {
"a" : {
"j" : 1
}
},
"waitForSync" : true,
"limit" : 2
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
Using Parameter: waitForSync and limit with new signature
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/remove-by-example <<EOF
{
"collection" : "products",
"example" : {
"a" : {
"j" : 1
}
},
"options" : {
"waitForSync" : true,
"limit" : 2
}
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"deleted" : 1,
"error" : false,
"code" : 200
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/remove-by-example <<EOF
{
"collection" : "products",
"example" : {
"a" : {
"j" : 1
}
},
"options" : {
"waitForSync" : true,
"limit" : 2
}
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
Replace documents by example
replaces the body of all documents of a collection that match anexample
PUT /_api/simple/replace-by-example
A JSON object with these properties is required:
-
collection: The name of the collection to replace within.
-
example: An example document that all collection documents are compared against.
-
newValue: The replacement document that will get inserted in place of the “old” documents.
-
options: a json object which can contain following attributes
- waitForSync: if set to true, then all removal operations will
instantly be synchronized to disk. If this is not specified, then the
collection’s default sync behavior will be applied.
- limit: an optional value that determines how many documents to
replace at most. If limit is specified but is less than the number
of documents in the collection, it is undefined which of the documents
will be replaced.
This will find all documents in the collection that match the specified example object, and replace the entire document body with the new value specified. Note that document meta-attributes such as _id, _key, _from, _to etc. cannot be replaced.
Note: the limit attribute is not supported on sharded collections. Using it will result in an error.
Returns the number of documents that were replaced.
Return codes
- waitForSync: if set to true, then all removal operations will
instantly be synchronized to disk. If this is not specified, then the
collection’s default sync behavior will be applied.
-
200: is returned if the query was executed successfully.
-
400: is returned if the body does not contain a valid JSON representation of a query. 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
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/replace-by-example <<EOF
{
"collection" : "products",
"example" : {
"a" : {
"j" : 1
}
},
"newValue" : {
"foo" : "bar"
},
"limit" : 3
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"replaced" : 1,
"error" : false,
"code" : 200
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/replace-by-example <<EOF
{
"collection" : "products",
"example" : {
"a" : {
"j" : 1
}
},
"newValue" : {
"foo" : "bar"
},
"limit" : 3
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
Using new Signature for attributes WaitForSync and limit
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/replace-by-example <<EOF
{
"collection" : "products",
"example" : {
"a" : {
"j" : 1
}
},
"newValue" : {
"foo" : "bar"
},
"options" : {
"limit" : 3,
"waitForSync" : true
}
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"replaced" : 1,
"error" : false,
"code" : 200
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/replace-by-example <<EOF
{
"collection" : "products",
"example" : {
"a" : {
"j" : 1
}
},
"newValue" : {
"foo" : "bar"
},
"options" : {
"limit" : 3,
"waitForSync" : true
}
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
Update documents by example
partially updates the body of all documents of a collection thatmatch an example
PUT /_api/simple/update-by-example
A JSON object with these properties is required:
-
collection: The name of the collection to update within.
-
example: An example document that all collection documents are compared against.
-
newValue: A document containing all the attributes to update in the found documents.
-
options: a json object which can contains following attributes:
- keepNull: This parameter can be used to modify the behavior when
handling null values. Normally, null values are stored in the
database. By setting the keepNull parameter to false, this
behavior can be changed so that all attributes in data with null
values will be removed from the updated document.
- waitForSync: if set to true, then all removal operations will
instantly be synchronized to disk. If this is not specified, then the
collection’s default sync behavior will be applied.
- limit: an optional value that determines how many documents to
update at most. If limit is specified but is less than the number
of documents in the collection, it is undefined which of the documents
will be updated.
- mergeObjectsc: Controls whether objects (not arrays) will be merged if present in both the
existing and the patch document. If set to false, the value in the
patch document will overwrite the existing document’s value. If set to
true, objects will be merged. The default is true.
This will find all documents in the collection that match the specified example object, and partially update the document body with the new value specified. Note that document meta-attributes such as _id, _key, _from, _to etc. cannot be replaced.
Note: the limit attribute is not supported on sharded collections. Using it will result in an error.
Returns the number of documents that were updated.
Return codes
- keepNull: This parameter can be used to modify the behavior when
handling null values. Normally, null values are stored in the
database. By setting the keepNull parameter to false, this
behavior can be changed so that all attributes in data with null
values will be removed from the updated document.
-
200: is returned if the collection was updated successfully and waitForSync was true.
-
400: is returned if the body does not contain a valid JSON representation of a query. 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
using old syntax for options
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/update-by-example <<EOF
{
"collection" : "products",
"example" : {
"a" : {
"j" : 1
}
},
"newValue" : {
"a" : {
"j" : 22
}
},
"limit" : 3
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"updated" : 1,
"error" : false,
"code" : 200
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/update-by-example <<EOF
{
"collection" : "products",
"example" : {
"a" : {
"j" : 1
}
},
"newValue" : {
"a" : {
"j" : 22
}
},
"limit" : 3
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
using new signature for options
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/update-by-example <<EOF
{
"collection" : "products",
"example" : {
"a" : {
"j" : 1
}
},
"newValue" : {
"a" : {
"j" : 22
}
},
"options" : {
"limit" : 3,
"waitForSync" : true
}
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"updated" : 1,
"error" : false,
"code" : 200
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/update-by-example <<EOF
{
"collection" : "products",
"example" : {
"a" : {
"j" : 1
}
},
"newValue" : {
"a" : {
"j" : 22
}
},
"options" : {
"limit" : 3,
"waitForSync" : true
}
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
First document of a collection
returns the first document(s) of a collection
PUT /_api/simple/first
A JSON object with these properties is required:
-
collection: the name of the collection
-
count: the number of documents to return at most. Specifying count is optional. If it is not specified, it defaults to 1.
This will return the first document(s) from the collection, in the order of
insertion/update time. When the count argument is supplied, the result
will be an array of documents, with the “oldest” document being first in the
result array.
If the count argument is not supplied, the result is the “oldest” document
of the collection, or null if the collection is empty.
Note: this method is not supported for sharded collections with more than
one shard.
Return codes
-
200: is returned when the query was successfully executed.
-
400: is returned if the body does not contain a valid JSON representation of a query. 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
Retrieving the first n documents
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/first <<EOF
{
"collection" : "products",
"count" : 2
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"result" : [
{
"_id" : "products/806504577",
"_key" : "806504577",
"_rev" : "806504577",
"i" : 1,
"a" : {
"k" : 1,
"j" : 1
}
},
{
"_id" : "products/806832257",
"_key" : "806832257",
"_rev" : "806832257",
"i" : 1,
"a" : {
"j" : 1
}
}
],
"error" : false,
"code" : 200
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/first <<EOF
{
"collection" : "products",
"count" : 2
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
Retrieving the first document
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/first <<EOF
{
"collection" : "products"
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"result" : {
"_id" : "products/811944065",
"_key" : "811944065",
"_rev" : "811944065",
"i" : 1,
"a" : {
"k" : 1,
"j" : 1
}
},
"error" : false,
"code" : 200
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/first <<EOF
{
"collection" : "products"
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
Last document of a collection
returns the last document(s) of a collection
PUT /_api/simple/last
A JSON object with these properties is required:
-
collection: the name of the collection
-
count: the number of documents to return at most. Specifying count is optional. If it is not specified, it defaults to 1.
This will return the last documents from the collection, in the order of
insertion/update time. When the count argument is supplied, the result
will be an array of documents, with the “latest” document being first in the
result array.
If the count argument is not supplied, the result is the “latest” document
of the collection, or null if the collection is empty.
Note: this method is not supported for sharded collections with more than
one shard.
Return codes
-
200: is returned when the query was successfully executed.
-
400: is returned if the body does not contain a valid JSON representation of a query. 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
Retrieving the last n documents
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/last <<EOF
{
"collection" : "products",
"count" : 2
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"result" : [
{
"_id" : "products/815679617",
"_key" : "815679617",
"_rev" : "815679617",
"i" : 1,
"a" : {
"k" : 2,
"j" : 2
}
},
{
"_id" : "products/815483009",
"_key" : "815483009",
"_rev" : "815483009",
"i" : 1
}
],
"error" : false,
"code" : 200
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/last <<EOF
{
"collection" : "products",
"count" : 2
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
Retrieving the first document
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/last <<EOF
{
"collection" : "products"
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
{
"result" : {
"_id" : "products/817318017",
"_key" : "817318017",
"_rev" : "817318017",
"i" : 1,
"a" : {
"k" : 2,
"j" : 2
}
},
"error" : false,
"code" : 200
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/last <<EOF
{
"collection" : "products"
}
EOF
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
Simple range query
returns all documents of a collection within a range
PUT /_api/simple/range
A JSON object with these properties is required:
-
collection: The name of the collection to query.
-
attribute: The attribute path to check.
-
left: The lower bound.
-
right: The upper bound.
-
closed: If true, use interval including left and right, otherwise exclude right, but include left.
-
skip: The number of documents to skip in the query (optional).
-
limit: The maximal amount of documents to return. The skip is applied before the limit restriction. (optional)
This will find all documents within a given range. In order to execute a
range query, a skip-list index on the queried attribute must be present.
Returns a cursor containing the result, see Http Cursor for details.
Note: the range simple query is deprecated as of ArangoDB 2.6.
The function may be removed in future versions of ArangoDB. The preferred
way for retrieving documents from a collection within a specific range
is to use an AQL query as follows:
FOR doc IN @@collection
FILTER doc.value >= @left && doc.value < @right
LIMIT @skip, @limit
RETURN doc`
Return codes
-
201: is returned if the query was executed successfully.
-
400: is returned if the body does not contain a valid JSON representation of a query. The response body contains an error document in this case.
-
404: is returned if the collection specified by collection is unknown or no suitable index for the range query is present. The response body contains an error document in this case.
Examples
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/range <<EOF
{
"collection" : "products",
"attribute" : "i",
"left" : 2,
"right" : 4
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
{
"result" : [
{
"_id" : "products/829048961",
"_key" : "829048961",
"_rev" : "829048961",
"i" : 2
},
{
"_id" : "products/829245569",
"_key" : "829245569",
"_rev" : "829245569",
"i" : 3
}
],
"hasMore" : false,
"count" : 2,
"error" : false,
"code" : 201
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/range <<EOF
{
"collection" : "products",
"attribute" : "i",
"left" : 2,
"right" : 4
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
Returns documents near a coordinate
returns all documents of a collection near a given location
PUT /_api/simple/near
A JSON object with these properties is required:
-
collection: The name of the collection to query.
-
latitude: The latitude of the coordinate.
-
longitude: The longitude of the coordinate.
-
distance: If given, the attribute key used to return the distance to the given coordinate. (optional). If specified, distances are returned in meters.
-
skip: The number of documents to skip in the query. (optional)
-
limit: The maximal amount of documents to return. The skip is applied before the limit restriction. The default is 100. (optional)
-
geo: If given, the identifier of the geo-index to use. (optional)
The default will find at most 100 documents near the given coordinate. The
returned array is sorted according to the distance, with the nearest document
being first in the return array. If there are near documents of equal distance, documents
are chosen randomly from this set until the limit is reached.
In order to use the near operator, a geo index must be defined for the
collection. This index also defines which attribute holds the coordinates
for the document. If you have more than one geo-spatial index, you can use
the geo field to select a particular index.
Returns a cursor containing the result, see Http Cursor for details.
Note: the near simple query is deprecated as of ArangoDB 2.6.
This API may be removed in future versions of ArangoDB. The preferred
way for retrieving documents from a collection using the near operator is
to issue an AQL query using the NEAR function as follows:
FOR doc IN NEAR(@@collection, @latitude, @longitude, @limit)
RETURN doc`
Return codes
-
201: is returned if the query was executed successfully.
-
400: is returned if the body does not contain a valid JSON representation of a query. 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
Without distance
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/near <<EOF
{
"collection" : "products",
"latitude" : 0,
"longitude" : 0,
"skip" : 1,
"limit" : 2
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
{
"result" : [
{
"_id" : "products/824133761",
"_key" : "824133761",
"_rev" : "824133761",
"name" : "Name/0.002/",
"loc" : [
0.002,
0
]
},
{
"_id" : "products/823740545",
"_key" : "823740545",
"_rev" : "823740545",
"name" : "Name/-0.002/",
"loc" : [
-0.002,
0
]
}
],
"hasMore" : false,
"count" : 2,
"error" : false,
"code" : 201
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/near <<EOF
{
"collection" : "products",
"latitude" : 0,
"longitude" : 0,
"skip" : 1,
"limit" : 2
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
With distance
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/near <<EOF
{
"collection" : "products",
"latitude" : 0,
"longitude" : 0,
"skip" : 1,
"limit" : 3,
"distance" : "distance"
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
{
"result" : [
{
"_id" : "products/826755201",
"_key" : "826755201",
"_rev" : "826755201",
"name" : "Name/-0.002/",
"loc" : [
-0.002,
0
],
"distance" : 222.38985328911744
},
{
"_id" : "products/827148417",
"_key" : "827148417",
"_rev" : "827148417",
"name" : "Name/0.002/",
"loc" : [
0.002,
0
],
"distance" : 222.38985328911744
},
{
"_id" : "products/826558593",
"_key" : "826558593",
"_rev" : "826558593",
"name" : "Name/-0.004/",
"loc" : [
-0.004,
0
],
"distance" : 444.779706578235
}
],
"hasMore" : false,
"count" : 3,
"error" : false,
"code" : 201
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/near <<EOF
{
"collection" : "products",
"latitude" : 0,
"longitude" : 0,
"skip" : 1,
"limit" : 3,
"distance" : "distance"
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
Find documents within a radius around a coordinate
returns all documents of a collection within a given radius
PUT /_api/simple/within
A JSON object with these properties is required:
-
collection: The name of the collection to query.
-
latitude: The latitude of the coordinate.
-
longitude: The longitude of the coordinate.
-
radius: The maximal radius (in meters).
-
distance: If given, the attribute key used to return the distance to the given coordinate. (optional). If specified, distances are returned in meters.
-
skip: The number of documents to skip in the query. (optional)
-
limit: The maximal amount of documents to return. The skip is applied before the limit restriction. The default is 100. (optional)
-
geo: If given, the identifier of the geo-index to use. (optional)
This will find all documents within a given radius around the coordinate
(latitude, longitude). The returned list is sorted by distance.
In order to use the within operator, a geo index must be defined for
the collection. This index also defines which attribute holds the
coordinates for the document. If you have more than one geo-spatial index,
you can use the geo field to select a particular index.
Returns a cursor containing the result, see Http Cursor for details.
Note: the within simple query is deprecated as of ArangoDB 2.6.
This API may be removed in future versions of ArangoDB. The preferred
way for retrieving documents from a collection using the near operator is
to issue an AQL query using the WITHIN function as follows:
FOR doc IN WITHIN(@@collection, @latitude, @longitude, @radius, @distanceAttributeName)
RETURN doc
Return codes
-
201: is returned if the query was executed successfully.
-
400: is returned if the body does not contain a valid JSON representation of a query. 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
Without distance
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/near <<EOF
{
"collection" : "products",
"latitude" : 0,
"longitude" : 0,
"skip" : 1,
"limit" : 2,
"radius" : 500
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
{
"result" : [
{
"_id" : "products/851462273",
"_key" : "851462273",
"_rev" : "851462273",
"name" : "Name/0.002/",
"loc" : [
0.002,
0
]
},
{
"_id" : "products/851069057",
"_key" : "851069057",
"_rev" : "851069057",
"name" : "Name/-0.002/",
"loc" : [
-0.002,
0
]
}
],
"hasMore" : false,
"count" : 2,
"error" : false,
"code" : 201
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/near <<EOF
{
"collection" : "products",
"latitude" : 0,
"longitude" : 0,
"skip" : 1,
"limit" : 2,
"radius" : 500
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
With distance
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/near <<EOF
{
"collection" : "products",
"latitude" : 0,
"longitude" : 0,
"skip" : 1,
"limit" : 3,
"distance" : "distance",
"radius" : 300
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
{
"result" : [
{
"_id" : "products/854083713",
"_key" : "854083713",
"_rev" : "854083713",
"name" : "Name/-0.002/",
"loc" : [
-0.002,
0
],
"distance" : 222.38985328911744
},
{
"_id" : "products/854476929",
"_key" : "854476929",
"_rev" : "854476929",
"name" : "Name/0.002/",
"loc" : [
0.002,
0
],
"distance" : 222.38985328911744
},
{
"_id" : "products/853887105",
"_key" : "853887105",
"_rev" : "853887105",
"name" : "Name/-0.004/",
"loc" : [
-0.004,
0
],
"distance" : 444.779706578235
}
],
"hasMore" : false,
"count" : 3,
"error" : false,
"code" : 201
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/near <<EOF
{
"collection" : "products",
"latitude" : 0,
"longitude" : 0,
"skip" : 1,
"limit" : 3,
"distance" : "distance",
"radius" : 300
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
Within rectangle query
returns all documents of a collection within a rectangle
PUT /_api/simple/within-rectangle
A JSON object with these properties is required:
-
collection: The name of the collection to query.
-
latitude1: The latitude of the first rectangle coordinate.
-
longitude1: The longitude of the first rectangle coordinate.
-
latitude2: The latitude of the second rectangle coordinate.
-
longitude2: The longitude of the second rectangle coordinate.
-
skip: The number of documents to skip in the query. (optional)
-
limit: The maximal amount of documents to return. The skip is applied before the limit restriction. The default is 100. (optional)
-
geo: If given, the identifier of the geo-index to use. (optional)
This will find all documents within the specified rectangle (determined by
the given coordinates (latitude1, longitude1, latitude2, longitude2).
In order to use the within-rectangle query, a geo index must be defined for
the collection. This index also defines which attribute holds the
coordinates for the document. If you have more than one geo-spatial index,
you can use the geo field to select a particular index.
Returns a cursor containing the result, see Http Cursor for details.
Return codes
-
201: is returned if the query was executed successfully.
-
400: is returned if the body does not contain a valid JSON representation of a query. 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
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/within-rectangle <<EOF
{
"collection" : "products",
"latitude1" : 0,
"longitude1" : 0,
"latitude2" : 0.2,
"longitude2" : 0.2,
"skip" : 1,
"limit" : 2
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
{
"result" : [
{
"_id" : "products/858081409",
"_key" : "858081409",
"_rev" : "858081409",
"name" : "Name/0.008/",
"loc" : [
0.008,
0
]
},
{
"_id" : "products/857884801",
"_key" : "857884801",
"_rev" : "857884801",
"name" : "Name/0.006/",
"loc" : [
0.006,
0
]
}
],
"hasMore" : false,
"count" : 2,
"error" : false,
"code" : 201
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/within-rectangle <<EOF
{
"collection" : "products",
"latitude1" : 0,
"longitude1" : 0,
"latitude2" : 0.2,
"longitude2" : 0.2,
"skip" : 1,
"limit" : 2
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
Fulltext index query
returns documents of a collection as a result of a fulltext query
PUT /_api/simple/fulltext
A JSON object with these properties is required:
-
collection: The name of the collection to query.
-
attribute: The attribute that contains the texts.
-
query: The fulltext query. Please refer to Fulltext queries for details.
-
skip: The number of documents to skip in the query (optional).
-
limit: The maximal amount of documents to return. The skip is applied before the limit restriction. (optional)
-
index: The identifier of the fulltext-index to use.
This will find all documents from the collection that match the fulltext
query specified in query.
In order to use the fulltext operator, a fulltext index must be defined
for the collection and the specified attribute.
Returns a cursor containing the result, see Http Cursor for details.
Note: the fulltext simple query is deprecated as of ArangoDB 2.6.
This API may be removed in future versions of ArangoDB. The preferred
way for retrieving documents from a collection using the near operator is
to issue an AQL query using the FULLTEXT AQL function
as follows:
FOR doc IN FULLTEXT(@@collection, @attributeName, @queryString, @limit)
RETURN doc
Return codes
-
201: is returned if the query was executed successfully.
-
400: is returned if the body does not contain a valid JSON representation of a query. 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
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/fulltext <<EOF
{
"collection" : "products",
"attribute" : "text",
"query" : "word"
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
{
"result" : [
{
"_id" : "products/813516929",
"_key" : "813516929",
"_rev" : "813516929",
"text" : "this text also has a word"
},
{
"_id" : "products/813320321",
"_key" : "813320321",
"_rev" : "813320321",
"text" : "this text contains word"
}
],
"hasMore" : false,
"count" : 2,
"error" : false,
"code" : 201
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/fulltext <<EOF
{
"collection" : "products",
"attribute" : "text",
"query" : "word"
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8