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.

createDocument #

Create a new document in Kuzzle and instantiate a Document object.


createDocument(Document, [options], [callback]) #

ArgumentsTypeDescription
DocumentobjectDocument object
optionsJSON objectOptional parameters
callbackfunctionOptional callback

createDocument([id], content, [options], [callback]) #

ArgumentsTypeDescription
idstringOptional document identifier
contentJSON objectContent of the document to create
optionsJSON objectOptional parameters
callbackfunctionOptional callback

Options #

OptionTypeDescriptionDefault
volatileJSON objectAdditional information passed to notifications to other usersnull
queuablebooleanMake this request queuable or nottrue
refreshstringIf set to wait_for, Kuzzle will wait for the persistence layer to finish indexing (available with Elasticsearch 5.x and above)undefined
ifExiststringIf the same document already exists: resolves to an error. Replaces the existing document if set to replacefalse

Return Value #

Returns the Collection object to allow chaining.


Callback Response #

Returns a Document object containing the newly created document.

Usage #

// Using callbacks (NodeJS or Web Browser)
kuzzle
  .collection('collection', 'index')
  .createDocument('foobar', {title: 'foo', content: 'bar'}, {ifExist: 'replace'}, function (err, res) {
    // callback called once the create action has been completed
    // => the result is a Document object
  });
// Using promises (NodeJS only)
kuzzle
  .collection('collection', 'index')
  .createDocumentPromise('foobar', {title: 'foo', content: 'bar'}, {ifExist: 'replace'})
  .then(res => {
    // promise resolved once the create action has been completed
    // => the result is a Document object
  });