1
0
Fork 0

Fix the examples for document manipulation.

This commit is contained in:
Wilfried Goesgens 2016-05-23 13:11:46 +02:00
parent c8a4a34fda
commit d8df82d714
3 changed files with 33 additions and 28 deletions

View File

@ -486,7 +486,7 @@ the result to be created.
Calls to the previous API can be translated as follows: Calls to the previous API can be translated as follows:
- old: GET `/_api/document?collection=<collection>&type=<type>` without HTTP request body - old: GET `/_api/document?collection=<collection>&type=<type>` without HTTP request body
- 3.0: PUT `/_api/simple/all-keys` with HTTP request body `{"name":"<collection>","type":"id"}` - 3.0: PUT `/_api/simple/all-keys` with HTTP request body `{"collection":"<collection>","type":"id"}`
The result format of this API has also changed slightly. In previous versions calls to The result format of this API has also changed slightly. In previous versions calls to
the API returned a JSON object with a `documents` attribute. As the functionality is the API returned a JSON object with a `documents` attribute. As the functionality is

View File

@ -121,7 +121,7 @@ key.
assert(response.code === 201); assert(response.code === 201);
logJsonResponse(response); logJsonResponse(response);
~ db._drop(cn); db._drop(cn);
@END_EXAMPLE_ARANGOSH_RUN @END_EXAMPLE_ARANGOSH_RUN
Create a document in a collection named *products* with a collection-level Create a document in a collection named *products* with a collection-level
@ -140,7 +140,7 @@ Create a document in a collection named *products* with a collection-level
assert(response.code === 202); assert(response.code === 202);
logJsonResponse(response); logJsonResponse(response);
~ db._drop(cn); db._drop(cn);
@END_EXAMPLE_ARANGOSH_RUN @END_EXAMPLE_ARANGOSH_RUN
Create a document in a collection with a collection-level *waitForSync* Create a document in a collection with a collection-level *waitForSync*
@ -151,7 +151,7 @@ value of *false*, but using the *waitForSync* query parameter.
db._drop(cn); db._drop(cn);
db._create(cn, { waitForSync: false }); db._create(cn, { waitForSync: false });
var url = "/_api/document/" + cn + "&waitForSync=true"; var url = "/_api/document/" + cn + "?waitForSync=true";
var body = '{ "Hello": "World" }'; var body = '{ "Hello": "World" }';
var response = logCurlRequest('POST', url, body); var response = logCurlRequest('POST', url, body);
@ -159,14 +159,13 @@ value of *false*, but using the *waitForSync* query parameter.
assert(response.code === 201); assert(response.code === 201);
logJsonResponse(response); logJsonResponse(response);
~ db._drop(cn); db._drop(cn);
@END_EXAMPLE_ARANGOSH_RUN @END_EXAMPLE_ARANGOSH_RUN
Unknown collection name Unknown collection name
@EXAMPLE_ARANGOSH_RUN{RestDocumentHandlerPostUnknownCollection1} @EXAMPLE_ARANGOSH_RUN{RestDocumentHandlerPostUnknownCollection1}
var cn = "products"; var cn = "products";
db._drop(cn);
var url = "/_api/document/" + cn; var url = "/_api/document/" + cn;
var body = '{ "Hello": "World" }'; var body = '{ "Hello": "World" }';
@ -183,6 +182,7 @@ Illegal document
@EXAMPLE_ARANGOSH_RUN{RestDocumentHandlerPostBadJson1} @EXAMPLE_ARANGOSH_RUN{RestDocumentHandlerPostBadJson1}
var cn = "products"; var cn = "products";
db._drop(cn); db._drop(cn);
db._create(cn);
var url = "/_api/document/" + cn; var url = "/_api/document/" + cn;
var body = '{ 1: "World" }'; var body = '{ 1: "World" }';
@ -192,40 +192,43 @@ Illegal document
assert(response.code === 400); assert(response.code === 400);
logJsonResponse(response); logJsonResponse(response);
db._drop(cn);
@END_EXAMPLE_ARANGOSH_RUN @END_EXAMPLE_ARANGOSH_RUN
Insert multiple documents: Insert multiple documents:
###!TODO, make this example work.
EXAMPLE_ARANGOSH_RUN{RestDocumentHandlerPostMulti} @EXAMPLE_ARANGOSH_RUN{RestDocumentHandlerPostMulti1}
var cn = "products"; var cn = "products";
db._drop(cn); db._drop(cn);
db._create(cn);
var url = "/_api/document/" + cn; var url = "/_api/document/" + cn;
var body = '[{"Hello":"Earth"}, {"Hello":"Venus"}, {"Hello":"Mars"}]'; var body = '[{"Hello":"Earth"}, {"Hello":"Venus"}, {"Hello":"Mars"}]';
var response = logCurlRequest('POST', url, body); var response = logCurlRequest('POST', url, body);
assert(response.code === 200); assert(response.code === 202);
logJsonResponse(response); logJsonResponse(response);
ND_EXAMPLE_ARANGOSH_RUN db._drop(cn);
@END_EXAMPLE_ARANGOSH_RUN
Use of returnNew: Use of returnNew:
###!TODO, make this example work.
EXAMPLE_ARANGOSH_RUN{RestDocumentHandlerPostMulti} @EXAMPLE_ARANGOSH_RUN{RestDocumentHandlerPostMulti2}
var cn = "products"; var cn = "products";
db._drop(cn); db._drop(cn);
db._create(cn);
var url = "/_api/document/" + cn + "?returnNew=true"; var url = "/_api/document/" + cn + "?returnNew=true";
var body = '{"Hello":"World"}'; var body = '{"Hello":"World"}';
var response = logCurlRequest('POST', url, body); var response = logCurlRequest('POST', url, body);
assert(response.code === 200); assert(response.code === 202);
logJsonResponse(response); logJsonResponse(response);
END_EXAMPLE_ARANGOSH_RUN db._drop(cn);
@END_EXAMPLE_ARANGOSH_RUN
@endDocuBlock @endDocuBlock

View File

@ -2,17 +2,17 @@
@startDocuBlock REST_DOCUMENT_READ_ALL @startDocuBlock REST_DOCUMENT_READ_ALL
@brief reads all documents from collection @brief reads all documents from collection
@RESTHEADER{GET /_api/document/{collection},Read all documents} @RESTHEADER{PUT /_api/simple/all-keys, Read all documents}
@RESTQUERYPARAMETERS @RESTQUERYPARAMETERS
@RESTQUERYPARAM{collection,string,optional} @RESTBODYPARAM{collection,string,optional}
The name of the collection. This is only for backward compatibility. The name of the collection. This is only for backward compatibility.
In ArangoDB versions < 3.0, the URL path was */_api/document* and In ArangoDB versions < 3.0, the URL path was */_api/document* and
this query parameter was required. This combination still works, but this was passed in via the query parameter "collection".
the recommended way is to specify the collection in the URL path. This combination was removed.
@RESTQUERYPARAM{type,string,optional} @RESTBODYPARAM{type,string,optional}
The type of the result. The following values are allowed: The type of the result. The following values are allowed:
- *id*: returns an array of document ids (*_id* attributes) - *id*: returns an array of document ids (*_id* attributes)
@ -29,7 +29,7 @@ not be relied on.
@RESTRETURNCODES @RESTRETURNCODES
@RESTRETURNCODE{200} @RESTRETURNCODE{201}
All went well. All went well.
@RESTRETURNCODE{404} @RESTRETURNCODE{404}
@ -47,14 +47,15 @@ Return all document paths
db.products.save({"hello1":"world1"}); db.products.save({"hello1":"world1"});
db.products.save({"hello2":"world1"}); db.products.save({"hello2":"world1"});
db.products.save({"hello3":"world1"}); db.products.save({"hello3":"world1"});
var url = "/_api/document/" + cn; var url = "/_api/simple/all-keys";
var body = {collection: cn};
var response = logCurlRequest('GET', url); var response = logCurlRequest('PUT', url, body);
assert(response.code === 200); assert(response.code === 201);
logJsonResponse(response); logJsonResponse(response);
~ db._drop(cn); db._drop(cn);
@END_EXAMPLE_ARANGOSH_RUN @END_EXAMPLE_ARANGOSH_RUN
Return all document keys Return all document keys
@ -67,14 +68,15 @@ Return all document keys
db.products.save({"hello1":"world1"}); db.products.save({"hello1":"world1"});
db.products.save({"hello2":"world1"}); db.products.save({"hello2":"world1"});
db.products.save({"hello3":"world1"}); db.products.save({"hello3":"world1"});
var url = "/_api/document/" + cn + "&type=key"; var url = "/_api/simple/all-keys";
var body = {collection: cn, type: "id"};
var response = logCurlRequest('GET', url); var response = logCurlRequest('PUT', url, body);
assert(response.code === 200); assert(response.code === 201);
logJsonResponse(response); logJsonResponse(response);
~ db._drop(cn); db._drop(cn);
@END_EXAMPLE_ARANGOSH_RUN @END_EXAMPLE_ARANGOSH_RUN
Collection does not exist Collection does not exist