mirror of https://gitee.com/bigwinds/arangodb
Fix the examples for document manipulation.
This commit is contained in:
parent
c8a4a34fda
commit
d8df82d714
|
@ -486,7 +486,7 @@ the result to be created.
|
|||
Calls to the previous API can be translated as follows:
|
||||
|
||||
- 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 API returned a JSON object with a `documents` attribute. As the functionality is
|
||||
|
|
|
@ -121,7 +121,7 @@ key.
|
|||
assert(response.code === 201);
|
||||
|
||||
logJsonResponse(response);
|
||||
~ db._drop(cn);
|
||||
db._drop(cn);
|
||||
@END_EXAMPLE_ARANGOSH_RUN
|
||||
|
||||
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);
|
||||
|
||||
logJsonResponse(response);
|
||||
~ db._drop(cn);
|
||||
db._drop(cn);
|
||||
@END_EXAMPLE_ARANGOSH_RUN
|
||||
|
||||
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._create(cn, { waitForSync: false });
|
||||
|
||||
var url = "/_api/document/" + cn + "&waitForSync=true";
|
||||
var url = "/_api/document/" + cn + "?waitForSync=true";
|
||||
var body = '{ "Hello": "World" }';
|
||||
|
||||
var response = logCurlRequest('POST', url, body);
|
||||
|
@ -159,14 +159,13 @@ value of *false*, but using the *waitForSync* query parameter.
|
|||
assert(response.code === 201);
|
||||
|
||||
logJsonResponse(response);
|
||||
~ db._drop(cn);
|
||||
db._drop(cn);
|
||||
@END_EXAMPLE_ARANGOSH_RUN
|
||||
|
||||
Unknown collection name
|
||||
|
||||
@EXAMPLE_ARANGOSH_RUN{RestDocumentHandlerPostUnknownCollection1}
|
||||
var cn = "products";
|
||||
db._drop(cn);
|
||||
|
||||
var url = "/_api/document/" + cn;
|
||||
var body = '{ "Hello": "World" }';
|
||||
|
@ -183,6 +182,7 @@ Illegal document
|
|||
@EXAMPLE_ARANGOSH_RUN{RestDocumentHandlerPostBadJson1}
|
||||
var cn = "products";
|
||||
db._drop(cn);
|
||||
db._create(cn);
|
||||
|
||||
var url = "/_api/document/" + cn;
|
||||
var body = '{ 1: "World" }';
|
||||
|
@ -192,40 +192,43 @@ Illegal document
|
|||
assert(response.code === 400);
|
||||
|
||||
logJsonResponse(response);
|
||||
db._drop(cn);
|
||||
@END_EXAMPLE_ARANGOSH_RUN
|
||||
|
||||
Insert multiple documents:
|
||||
###!TODO, make this example work.
|
||||
|
||||
EXAMPLE_ARANGOSH_RUN{RestDocumentHandlerPostMulti}
|
||||
@EXAMPLE_ARANGOSH_RUN{RestDocumentHandlerPostMulti1}
|
||||
var cn = "products";
|
||||
db._drop(cn);
|
||||
db._create(cn);
|
||||
|
||||
var url = "/_api/document/" + cn;
|
||||
var body = '[{"Hello":"Earth"}, {"Hello":"Venus"}, {"Hello":"Mars"}]';
|
||||
|
||||
var response = logCurlRequest('POST', url, body);
|
||||
|
||||
assert(response.code === 200);
|
||||
assert(response.code === 202);
|
||||
|
||||
logJsonResponse(response);
|
||||
ND_EXAMPLE_ARANGOSH_RUN
|
||||
db._drop(cn);
|
||||
@END_EXAMPLE_ARANGOSH_RUN
|
||||
|
||||
Use of returnNew:
|
||||
###!TODO, make this example work.
|
||||
|
||||
EXAMPLE_ARANGOSH_RUN{RestDocumentHandlerPostMulti}
|
||||
@EXAMPLE_ARANGOSH_RUN{RestDocumentHandlerPostMulti2}
|
||||
var cn = "products";
|
||||
db._drop(cn);
|
||||
db._create(cn);
|
||||
|
||||
var url = "/_api/document/" + cn + "?returnNew=true";
|
||||
var body = '{"Hello":"World"}';
|
||||
|
||||
var response = logCurlRequest('POST', url, body);
|
||||
|
||||
assert(response.code === 200);
|
||||
assert(response.code === 202);
|
||||
|
||||
logJsonResponse(response);
|
||||
END_EXAMPLE_ARANGOSH_RUN
|
||||
db._drop(cn);
|
||||
@END_EXAMPLE_ARANGOSH_RUN
|
||||
@endDocuBlock
|
||||
|
||||
|
|
|
@ -2,17 +2,17 @@
|
|||
@startDocuBlock REST_DOCUMENT_READ_ALL
|
||||
@brief reads all documents from collection
|
||||
|
||||
@RESTHEADER{GET /_api/document/{collection},Read all documents}
|
||||
@RESTHEADER{PUT /_api/simple/all-keys, Read all documents}
|
||||
|
||||
@RESTQUERYPARAMETERS
|
||||
|
||||
@RESTQUERYPARAM{collection,string,optional}
|
||||
@RESTBODYPARAM{collection,string,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.
|
||||
this was passed in via the query parameter "collection".
|
||||
This combination was removed.
|
||||
|
||||
@RESTQUERYPARAM{type,string,optional}
|
||||
@RESTBODYPARAM{type,string,optional}
|
||||
The type of the result. The following values are allowed:
|
||||
|
||||
- *id*: returns an array of document ids (*_id* attributes)
|
||||
|
@ -29,7 +29,7 @@ not be relied on.
|
|||
|
||||
@RESTRETURNCODES
|
||||
|
||||
@RESTRETURNCODE{200}
|
||||
@RESTRETURNCODE{201}
|
||||
All went well.
|
||||
|
||||
@RESTRETURNCODE{404}
|
||||
|
@ -47,14 +47,15 @@ Return all document paths
|
|||
db.products.save({"hello1":"world1"});
|
||||
db.products.save({"hello2":"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);
|
||||
~ db._drop(cn);
|
||||
db._drop(cn);
|
||||
@END_EXAMPLE_ARANGOSH_RUN
|
||||
|
||||
Return all document keys
|
||||
|
@ -67,14 +68,15 @@ Return all document keys
|
|||
db.products.save({"hello1":"world1"});
|
||||
db.products.save({"hello2":"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);
|
||||
~ db._drop(cn);
|
||||
db._drop(cn);
|
||||
@END_EXAMPLE_ARANGOSH_RUN
|
||||
|
||||
Collection does not exist
|
||||
|
|
Loading…
Reference in New Issue