mCreate

Creates multiple documents.

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

Signature

Copied to clipboard!
std::string mCreate(
    const std::string& index,
    const std::string& collection,
    const std::string& documents);

std::string mCreate(
    const std::string& index,
    const std::string& collection,
    const std::string& documents,
    const kuzzleio::query_options& options);

Arguments

Argument Type Description
index
const std::string&
Index name
collection
const std::string&
Collection name
documents
const std::string&
JSON string representing the documents to create
options
kuzzleio::query_options*
Query options

options

Additional query options

Option Type
(default)
Description
queuable
bool

(true)
If true, queues the request during downtime, until connected to Kuzzle again
refresh
const std::string&
("")
If set to wait_for, waits for the change to be reflected for search (up to 1s)

Return

A JSON string containing an array representing the created documents.

Exceptions

Throws a kuzzleio::KuzzleException if there is an error. See how to handle errors.

Usage

Copied to clipboard!
std::string documents = R"([
  {
    "_id": "some-id",
    "body": { "capacity": 4 }
  },
  {
    "body": { "this": "document id is auto-computed" }
  }
])";

try {
  std::string response = kuzzle->document->mCreate(
    "nyc-open-data",
    "yellow-taxi",
    documents);

  std::cout << response << std::endl;
  /*
  [
    {
      "_id":"some-id",
      "_source":{
        "_kuzzle_info":{
          "active":true,
          "author":"-1",
          "updater":null,
          "updatedAt":null,
          "deletedAt":null,
          "createdAt":1538470871764
        },
        "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":"AWY0AoLgKWETYfLdcMat",
      "_source":{
        "_kuzzle_info":{
          "active":true,
          "author":"-1",
          "updater":null,
          "updatedAt":null,
          "deletedAt":null,
          "createdAt":1538470871764
        },
        "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
    }
  ]
  */

  std::cout << "Documents successfully created" << std::endl;
} catch (kuzzleio::KuzzleException& e) {
  std::cerr << e.what() << std::endl;
}