Step 4: Reading
In this step, we will read data we wrote to the database in Step 3
Fetching a single item
To fetch a single item, use the getItem
method. Let's fetch the item with the key job#1
:
- JavaScript
- Python
const document = await client.getItem({databaseId, key: 'job#1'});
console.log(document);
document = await client.get_item(GetItemInput(database_id=databaseId, key="job#1"))
print(document)
Listing all items
To list all items in the database, use the listItems
method. By default, this method returns 1,000 items. You can paginate through the results by passing the nextToken
returned in the response.
- JavaScript
- Python
const documents = await client.listItems({databaseId});
console.log(`Found ${documents.items.length} documents`)
console.log(documents);
documents = await client.list_items(ListItemsInput(database_id=databaseId))
print(f"Found {len(documents.items)} documents")
print(documents)