POST /{db}/_bulk_docs
This request enables you to add, update, or delete multiple documents to a database in a single request.
To add new documents, you can either specify the ID (_id) or let the software create an
ID.
To update existing documents, you must provide the document ID, revision
identifier (_rev), and new document values.
To delete existing documents you must provide the document ID, revision identifier,
and the deletion flag (_deleted).
Request
Request headers
This request does not have any required headers.
Query parameters
This request does not use query parameters.
Message body
The message body is a JSON document that contains the following objects:
| Name | Type | Description | Default |
|---|---|---|---|
all_or_nothing | Boolean | Optional. Indicates whether to use all-or-nothing semantics for the database commit mode | false |
docs | array | List containing new or updated documents. Each object in the array can contain
the following properties: _id, _rev,
_deleted, and values for new and updated documents. | none |
new_edits | Boolean | Optional. Indicates whether to assign new revision identifiers to new edits. | true |
Response
Status codes
- 201 Created – Document(s) have been created or updated
- 400 Bad Request – The request provided invalid JSON data
- 417 Expectation Failed – Occurs when all_or_nothing option set as true and at least one document was rejected by validation function
- 500 Internal Server Error – Malformed data provided, while it’s still valid JSON
Response headers
This response uses only standard HTTP headers.
Message body
The response message body is a JSON documental that contains an array. Each array element contains the following objects:
| Name | Type | Description |
|---|---|---|
id | String | Document identifier |
ok | Boolean | Indicates whether the operation was successful |
rev | String | revision identifier |
Example
Request
The following example adds a new document with the identifier
PeachCobbler, modifies the document with the identifier
LemonChicken, and deletes the document with the identifier
CinnamonCookies.
POST /cookbook/_bulk_docs
Host: localhost:59840
{
"docs": [
{
"_id": "PeachCobbler",
"description": "Juicy peaches topped with pie crust",
"title": "Peach Cobbler"
},
{
"_id": "LemonChicken",
"_rev": "3-6210945863a15ee7eff1e540133d19da",
"description": "Chinese lemon chicken",
"serving-suggestion": "Serve with plain jasmine rice.",
"servings": 4,
"title": "Lemon Chicken"
},
{
"_deleted": true,
"_id": "CinnamonCookies",
"_rev": "1-2c25302ccf3d70d3461f28b8df9fafd0"
}
]
}
Response
HTTP/1.1 201 Created
Accept-Ranges: bytes
Content-Type: application/json
Date: Mon, 16 Dec 2013 17:01:56 GMT
Server: CouchbaseLite 1.486
Transfer-Encoding: chunked
[
{
"id" : "PeachCobbler",
"rev" : "1-eb8eafda1b60edecef37f7daa02baa9e",
"ok" : true
},
{
"id" : "LemonChicken",
"rev" : "4-51737756120a34de2d4981ab0f02c5a5",
"ok" : true
},
{
"id" : "CinnamonCookies",
"rev" : "2-28df61cdda892ad3dd4339f2bce18463",
"ok" : true
}
]