SDK
SDK Javascript v6.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.

mCreateOrReplace #

Creates or replaces multiple documents.

Throws a partial error (error code 206) if one or more document creations/replacements fail.


Copied to clipboard!
mCreateOrReplace(index, collection, documents, [options]);
Argument Type Description
index string Index name
collection string Collection name
documents array<object> Array of documents to create
options object Query options

Options #

Additional query options

Options Type
(default)
Description
queuable boolean
(true)
If true, queues the request during downtime, until connected to Kuzzle again
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 created documents.

Property Type Description
hits array<object> Created documents
total number Total number of created documents

Usage #

Copied to clipboard!
try {
  const documents = [
    {
      _id: 'some-id',
      body: { 'capacity': 4 }
    },
    {
      _id: 'some-other-id',
      body: { 'capacity': 4 }
    }
  ];
  const response = await kuzzle.document.mCreateOrReplace(
    'nyc-open-data',
    'yellow-taxi',
    documents
  );
  console.log(JSON.stringify(response));
  /*
    {
      "hits": [
        {
          "_id": "some-id",
          "_source": {
            "_kuzzle_info": {
              "active": true,
              "author": "-1",
              "updater": null,
              "updatedAt": null,
              "deletedAt": null,
              "createdAt": 1542036740596
            },
            "capacity": 4
          },
          "_index": "nyc-open-data",
          "_type": "yellow-taxi",
          "_version": 1,
          "result": "created",
          "_shards": {
            "total": 2,
            "successful": 1,
            "failed": 0
          },
          "created": true,
          "status": 201
        },
        {
          "_id": "some-other-id",
          "_source": {
            "_kuzzle_info": {
              "active": true,
              "author": "-1",
              "updater": null,
              "updatedAt": null,
              "deletedAt": null,
              "createdAt": 1542036740596
            },
            "capacity": 4
          },
          "_index": "nyc-open-data",
          "_type": "yellow-taxi",
          "_version": 1,
          "result": "created",
          "_shards": {
            "total": 2,
            "successful": 1,
            "failed": 0
          },
          "created": true,
          "status": 201
        }
      ],
      "total": 2
    }
  */
  console.log(`Successfully createOrReplace ${response.total} documents`);
} catch (error) {
  console.error(error.message);
}