Documents

Replace documents

Replaces multiple documents in the specified collection with the ones in the body. The replaced documents are specified by the _key attributes in the body documents.

If ignoreRevs is false,, a _rev attribute in each document body must match the revision of the corresponding document in the database. Otherwise, the call fails

If the document exists and can be updated, a HTTP 201 or a HTTP 202 is returned (depending on waitForSync, see below).

The body of the response contains a JSON array of the same length as the input array with the information about the handle and the revision of the replaced documents. In each entry:

  • _id contains the known document-handle of each updated document.
  • _key contains the key which uniquely identifies a document.
  • _rev contains the new document revision.

In case of an error or violated precondition, an error object with the attribute error set to true and the attribute errorCode set to the error code.

If the query parameter returnOld is true, for each generated document the previous revision of the document is returned under the old attribute in the result.

If the query parameter returnNew is true, for each generated document the new document is returned under the new attribute in the result.

Note that if any precondition is violated or an error occurred with some of the documents, the return code is still 201 or 202, but the additional HTTP header X-C8-Error-Codes is set, that contains a map of the error codes that occurred together with their multiplicities, as in: 1200:17,1205:10 which means that in 17 cases the error 1200 "revision conflict" and in 10 cases the error 1205 "illegal document handle" has happened.

put/_fabric/{fabric}/_api/document/{collection}

Request

Path parameters

fabricstring string required

The name of the fabric.

collectionstring string required

This URL parameter is the name of the collection in which the documents are replaced.

Query parameters

ignoreRevsboolean

If this is set to true, the _rev attributes in the given documents are ignored. If this is set to false, any _rev attribute given in a body document is taken as a precondition. The document is only replaced if the current revision is the one specified.

returnOldboolean

If set to true, adds the old attribute which displays document revisions.

returnNewboolean

If set to true, adds the new documents to the new attribute.

waitForSyncboolean

If set to true, returns only after data has been synced to disk.

Request body

object required

Response

Successfully replaced documents when waitForSync is enabled.

_idstring

ID of the collection.

_keystring

_key details of collection.

_revstring

_rev details of collection.

Example response

[
  {
    "_id": "test/foo",
    "_key": "foo",
    "_rev": "_dPRuHxe--_"
  }
]

Changes

No recorded changes to this operation across all 1 revision of this API.