SDK
SDK Javascript v5.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

mCreateOrReplaceDocument #

Create or replace the input Documents.


mCreateOrReplaceDocument(documents, [options], [callback]) #

ArgumentsTypeDescription
documentsDocument[]Array of Document to create or replace
optionsJSON ObjectOptional parameters
callbackfunctionOptional callback

Options #

OptionTypeDescriptionDefault
queuablebooleanMake this request queuable or nottrue

Return Value #

Returns the Collection object to allow chaining.


Callback Response #

Returns a JSON object containing the raw Kuzzle response. Can return a 206 partial error in cases where some documents could not be created or replaced.

Usage #

var
  Document = require('./src/Document'),
  firstDocument = new Document(collection, 'doc1', {title: 'foo', content: 'bar'}),
  secondDocument = new Document(collection, 'doc2', {title: 'foo', content: 'bar'});
// Using callbacks (NodeJS or Web Browser)
kuzzle
  .collection('collection', 'index')
  .mCreateOrReplaceDocument([firstDocument, secondDocument], function (error, result) {
    // callback called once the mCreateOrReplace operation has completed
    // => the result is a JSON object containing the raw Kuzzle response
  });
// Using promises (NodeJS only)
kuzzle
  .collection('collection', 'index')
  .mCreateOrReplaceDocumentPromise([firstDocument, secondDocument])
  .then(result => {
    // promise resolved once the mCreateOrReplace operation has completed
    // => the result is a JSON object containing the raw Kuzzle response
  });

Callback response:

{
  "hits": [{ "first": "document" }, { "second": "document" }],
  "total": 2
}