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.

mCreate #

Creates multiple documents.

Throws a partial error (error code 206) if one or more documents creations fail.


mCreate(index, collection, documents, [options]);
ArgumentTypeDescription
indexstringIndex name
collectionstringCollection name
documentsarray<object>Array of documents to create
optionsobjectQuery options

Options #

Additional query options

OptionsType
(default)
Description
queuableboolean
(true)
If true, queues the request during downtime, until connected to Kuzzle again
refreshstring
("")
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.

PropertyTypeDescription
hitsarray<object>Created documents
totalnumberTotal number of created documents

Usage #

try {
  const documents = [
    {
      _id: 'some-id',
      body: { 'capacity': 4 }
    },
    {
      body: { this: 'document id is auto-computed' }
    }
  ];
  const response = await kuzzle.document.mCreate(
    'nyc-open-data',
    'yellow-taxi',
    documents
  );
  console.log(response);
  /*
  {
    "hits": [
      {
        "_id": "some-id",
        "_source": {
          "_kuzzle_info": {
            "active": true,
            "author": "-1",
            "updater": null,
            "updatedAt": null,
            "deletedAt": null,
            "createdAt": 1542036563677
          },
          "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": "AWcIiqbeBiYFF8kkRLKg",
        "_source": {
          "_kuzzle_info": {
            "active": true,
            "author": "-1",
            "updater": null,
            "updatedAt": null,
            "deletedAt": null,
            "createdAt": 1542036563677
          },
          "this": "document id is auto-computed"
        },
        "_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 created ${response.total} documents`);
} catch (error) {
  console.error(error.message);
}