Using multiGet()

Store.multiGet() allows you to retrieve multiple rows at once, so long as they all share the same shard keys. You must specify a full set of shard keys to this method.

Use Store.multiGet() only if your retrieval set will fit entirely in memory.

For example, suppose you have a table that stores information about products, which is designed like this:

CREATE TABLE myTable (
    itemType STRING,
    itemCategory STRING,
    itemClass STRING,
    itemColor STRING,
    itemSize STRING,
    price FLOAT,
    inventoryCount INTEGER,
    PRIMARY KEY (SHARD(itemType, itemCategory, itemClass), itemColor,
    itemSize)
) 

With tables containing data like this:

In this case, you can retrieve all of the rows with their itemType field set to Hats and their itemCategory field set to baseball. Notice that this represents a partial primary key, because itemClass, itemColor and itemSize are not used for this query.

...
// Store handle configuration and open skipped for brevity
...

store.on('open', function () {
   console.log('Store opened');

   var shardKey = {itemType: "Hats", 
                   itemCategory: "baseball",
                  itemClass: "longbill"};


   store.multiGet('myTable', shardKey, null,
           function (err, result) {
                if (err)
                    throw err;
                else {
                    console.log("Retrieved rows:");

                    for (var key in result.returnRows)
                         console.log(result.returnRows[key].row);

                    store.close();
                }
           });
}).on('close', function() {
    console.log('Store closed.');
}).on('error', function(error) {
    console.log(error);
});
store.open(); 

Notice in the previous example that you can iterate over the results, which are returned in a MultiGetResult object. This object contains the result set in an array held by the returnRows property. Each element in this array provides the retrieved row (accessible using the row property), as well as the table name (returnRows[x].table) and row version information (returnRows[x].version).