mGet

Gets multiple documents.

Throws a partial error (error code 206) if one or more document can not be retrieved.

Signature

Copied to clipboard!
std::string mGet(
    const std::string& index,
    const std::string& collection,
    const std::vector<std::string>& ids);

std::string mGet(
    const std::string& index,
    const std::string& collection,
    const std::vector<std::string>& ids,
    const kuzzleio::query_options& options);

Arguments

Argument Type Description
index
const std::string&
Index name
collection
const std::string&
Collection name
ids
std::vector<std::string>
Document IDs
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

Return

A JSON string representing an array of objects containing the following properties:

Property Type Description
_id_
string
Document ID
_source_
object
Document content

Exceptions

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

Usage

Copied to clipboard!
std::vector<std::string> ids;

ids.push_back("some-id");
ids.push_back("some-other-id");

try {
  kuzzle->document->create("nyc-open-data", "yellow-taxi", "some-id", R"({"capacity": 4})");
  kuzzle->document->create("nyc-open-data", "yellow-taxi", "some-other-id", R"({"capacity": 7})");

  std::string response = kuzzle->document->mGet(
    "nyc-open-data",
    "yellow-taxi",
    ids);

  std::cout << response << std::endl;
  /*
    [
      {
        "_index": "nyc-open-data",
        "_type": "yellow-taxi",
        "_id": "some-id",
        "_version": 1,
        "found": true,
        "_source": {
          "capacity": 4,
          "_kuzzle_info": {
            "author": "-1",
            "createdAt": 1545411356404,
            "updatedAt": null,
            "updater": null,
            "active": true,
            "deletedAt": null
          }
        }
      },
      {
        "_index": "nyc-open-data",
        "_type": "yellow-taxi",
        "_id": "some-other-id",
        "_version": 1,
        "found": true,
        "_source": {
          "capacity": 7,
          "_kuzzle_info": {
            "author": "-1",
            "createdAt": 1545411356424,
            "updatedAt": null,
            "updater": null,
            "active": true,
            "deletedAt": null
          }
        }
      }
    ]
  */
  std::cout << "Successfully retrieved 2 documents" << std::endl;
} catch (kuzzleio::KuzzleException& e) {
  std::cerr << e.what() << std::endl;
}