Core
Framework v2.x
2

createOrReplace() #

Creates or replaces a document.

Arguments #

createOrReplace(document: JSONObject, options?: JSONObject): Promise<JSONObject>;

ArgumentsTypeDescription
document
JSONObject
The document to create. The provided object must contain a _id property, which is the document unique identifier
options
JSONObject
Optional arguments

options #

The options argument accepts the following parameters:

OptionsTypeDescription
refresh
string
If set with the wait_for string value, then the function will respond only after the document has been indexed

Return #

The createOrReplace function returns a promise, resolving to the document creation or replacement result, with the following properties:

FieldTypeDescription
_id
string
Document unique identifier
_version
integer
Document version
_source
JSONObject
Document content, including the _kuzzle_info metadata
created
boolean
true if the document was created, false if it was replaced

Example #

const content = {
  _id: '<unique id>',
  someField: 'some content',
  anotherField: 'another content'
};

const result = await repository.createOrReplace(content);
/*
  * { _id: '<unique id>',
  *   _version: 1,
  *   created: true,
  *   _source: {
  *     someField: 'some content',
  *     anotherField: 'another content',
  *     _kuzzle_info: {
  *       author: null,
  *       createdAt: 1700000000000,
  *       updatedAt: null,
  *       updater: null
  *     }
  *   }
  * }
  */