SDK
SDK Javascript v6.x
1

# write

Available since 6.2.0
Available since Kuzzle 1.8.0

Creates or replaces a document directly into the storage engine.

This is a low level route intended to bypass Kuzzle actions on document creation, notably:


Copied to clipboard!
write (index, collection, document, [id], [options])

Argument Type Description
index
string
Index name
collection
string
Collection name
document
object
Document content
id
string
Optional document ID
options
object
Query options

# options

Additional query options

Property Type
(default)
Description
queuable
boolean

(true)
If true, queues the request during downtime, until connected to Kuzzle again
notify
boolean

(false)
if set to true, Kuzzle will trigger realtime notifications
refresh
string

("")
If set to wait_for, waits for the change to be reflected for search (up to 1s)

# Resolves

Resolves to an object containing the document creation result.

Name Type Description
_id
string
ID of the newly created document
_version
number
Version of the document in the persistent data storage
_source
object
Created document

# Usage

Copied to clipboard!
try {
  const document = {
    licence: 'B',
    _kuzzle_info: {
      creator: 'liia',
      createdAt: 653132233
    }
  };
  const result = await kuzzle.bulk.write(
    'nyc-open-data',
    'yellow-taxi',
    document
  );
  console.log(result);
  /*
  { _id: 'AWvljct6E7sKlamkyoHl',
    _version: 1,
    _source:
      { licence: 'B',
        _kuzzle_info: { creator: 'liia', createdAt: 653132233 } }
  */
  console.log(`Document creator is ${result._source._kuzzle_info.creator}`);
} catch (error) {
  console.error(error.message);
}