SDK
SDK Javascript v7.x
2

mGet #

Gets multiple documents.


Copied to clipboard!
mGet(index, collection, ids, [options]);
Argument Type Description
index
string
Index name
collection
string
Collection name
ids
string[]
Document ids
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
verb
string
(HTTP only) Forces the verb of the route
timeout
number
Time (in ms) during which a request will still be waited to be resolved. Set it -1 if you want to wait indefinitely

verb #

When instantiated with a HTTP protocol object, the SDK uses the GET API by default for this API route. You can set the verb option to POST to force the SDK to use the POST API instead.

Resolves #

Returns an object containing 2 arrays: successes and errors

The successes array contain the list of retrieved documents.

Each document have the following properties:

Name Type Description
_id
string
Document ID
_version
number
Version of the document in the persistent data storage
_source
object
Document content

The errors array contain the IDs of not found documents.

Usage #

Copied to clipboard!
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);
  /*
    {
      "successes": [
        { "_id": "some-id",
          "_version": 1,
          "found": true,
          "_source": {
            "capacity": 4,
            "_kuzzle_info": {
              "author": "-1",
              "createdAt": 1542036871353,
              "updatedAt": null,
              "updater": null
            }
          }
        },
        { "_id": "some-other-id",
          "_version": 1,
          "found": true,
          "_source": {
            "capacity": 7,
            "_kuzzle_info": {
              "author": "-1",
              "createdAt": 1542036871374,
              "updatedAt": null,
              "updater": null
            }
          }
        }
      ],
      "errors": []
    }
  */
  console.log(`Successfully get ${response.successes.length} documents`);
} catch (error) {
  console.error(error.message);
}