Create document
Create a new document from the document given in the body, unless there is already a document with the _key given. If no _key is given, a new unique _key is generated automatically.
The body can be an array of documents, in which case all documents in the array are inserted with the same semantics as for a single document. The result body contains a JSON array of the same length as the input array, and each entry contains the result of the operation for the corresponding input. In case of an error the entry is a document with attributes error set to true and errorCode set to the error code that has happened.
Possibly given _id and _rev attributes in the body are always ignored, the URL part or the query parameter collection respectively counts.
If the document is created successfully, the Location header contains the path to the newly created document. The Etag header field contains the revision of the document. Both are only set in the single document case.
If silent is not set to true, the body of the response contains a JSON object (single document case) with the following attributes:
- _id contains the document handle of the newly created document.
- _key contains the document key.
- _rev contains the document revision.
In the multi case the body is an array of such objects. If the query parameter returnNew is true, then, for each generated document, the new document is returned under the new attribute in the result.
Request
- The document declares no server URL.
- Auth
- API key in header Authorization
- or HTTP bearer
- TypeScriptA function with typed inputs. Its response is checked against the schema.
Path parameters
The name of the fabric.
The collection in which the document is to be created.
Query parameters
The name of the collection. This is only for backward compatibility.
If set to true, adds the new documents to the new attribute.
If set to true, adds the old attribute which displays the previous version of the document. Only available if the overwrite option is set to true.
If set to true, an empty object is returned as response. No meta-data is returned for the created document. This option can be used to save some network traffic.
If set to true, the insert becomes a replace-insert. If a document with the same _key already exists the new document is not rejected with unique constraint violated but replaces the old document.
If set to true, returns only after data has been synced to disk.
Request body
Example request
[
{
"item1": "data1"
},
{
"item2": "data2"
}
]Response
Successfully created documents when waitForSync is enabled. If more than one document is specified in the JSON body, check the response body to verify the creations succeeded.
Example response
[
{
"_id": "test/foo",
"_key": "foo",
"_rev": "_dPRuHxe--_"
}
]Changes
No recorded changes to this operation across all 1 revision of this API.