Fetch Items from NoSQL Table

Catalyst enables you to fetch items from a NoSQL table by identifying them with their primary keys. For instance, you can use just the partition key or a combination of the partition key and sort key to fetch the item. You can also optionally filter the attributes to be fetched by specifying the required attributes.

Note: Catalyst enables you to fetch a maximum of 100 items from a NoSQL table in a single SDK read operation.

The example below illustrates fetching an item identified by its partition key fruit with the value “apple” using fetchItem(). Specific attributes such as properties and taste are filtered to be fetched using required_attributes.

The code snippet also uses consistent_read to indicate if the read operation must be done using the master or a slave cluster. When set to true, it is queried from the master. If false, it is queried from the slave.

Note: In the master-slave replication, the master contains all the data of the database, and the slave contains copies from the master. Performing a read operation from the slave can reduce the overall cost with the trade-off being a minor delay in the updated data being reflected.

The no-sql library from the zcatalyst-sdk-node package is required to define the NoSQL item.

    
copy
const { NoSQLItem } = require('zcatalyst-sdk-node/lib/no-sql'); //Fetch properties of a NoSQLItem identified with the partition key value "apple" const fetchedItem = await table.fetchItem({ // Define the partition key and value of the item to be fetched keys: [new NoSQLItem().addString('fruit', 'apple')], // Set consistent_read to true to query from master. If set to false, it is queried from slave. consistent_read: true, // Specify the attributes to be fetched required_attributes: [['properties', 'taste']] });

Last Updated 2025-06-20 16:21:48 +0530 +0530

ON THIS PAGE