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.

mGet #

Gets multiple documents.

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


mGet(index, collection, ids, [options]);
ArgumentTypeDescription
indexstringIndex name
collectionstringCollection name
idsarray<string>Document ids
optionsobjectQuery options

Options #

Additional query options

OptionsType
(default)
Description
queuableboolean
(true)
If true, queues the request during downtime, until connected to Kuzzle again

Resolves #

Resolves to an object containing the retrieved documents.

PropertyTypeDescription
hitsarray<object>Retrieved documents
totalnumberTotal retrieved documents

Usage #

const doc1 = { capacity: 4 };
const doc2 = { capacity: 7 };
try {
  await kuzzle.document.create('nyc-open-data', 'yellow-taxi', doc1, 'some-id');
  await kuzzle.document.create('nyc-open-data', 'yellow-taxi', doc2, 'some-other-id');
  const response = await kuzzle.document.mGet(
    'nyc-open-data',
    'yellow-taxi',
    ['some-id', 'some-other-id']
  );
  console.log(response);
  /*
    {
      "hits": [
        {
          "_index": "nyc-open-data",
          "_type": "yellow-taxi",
          "_id": "some-id",
          "_version": 1,
          "found": true,
          "_source": {
            "capacity": 4,
            "_kuzzle_info": {
              "author": "-1",
              "createdAt": 1542036871353,
              "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": 1542036871374,
              "updatedAt": null,
              "updater": null,
              "active": true,
              "deletedAt": null
            }
          }
        }
      ],
      "total": 2
    }
  */
  console.log(`Successfully get ${response.total} documents`);
} catch (error) {
  console.error(error.message);
}