In DynamoDB, an item collection is a group of items that share the same partition key value, which means the items are related. Item collections are the primary mechanism to model one-to-many relationships in DynamoDB. Item collections can only exist on tables or indexes configured to use a composite primary key.
Consider the following table showing three different users and their in-game inventories:
For some items in each collection, the sort key is a concatenation made up of information used to group data, such as inventory::armor
, inventory::weapon
or info
. Each item collection can have a different combination of these attributes as the sort key. User account1234
has an inventory::weapons
item, while user account1387
does not (because they have not found any yet). User account1138
only uses two items for their sort key (since they have no inventory yet) while the other users use three.
DynamoDB lets you selectively retrieve items from these item collections to do the following:
Retrieve all items from a particular user
Retrieve only one item from a particular user
Retrieve all the items of a specific type belonging to a particular user
In this example, each of the items in these three item collections represents a player and the data model we have chosen, based off the gameâs and playerâs access patterns. What data does the game need? When does it need it? How frequently does it need it? Whatâs the cost of doing it this way? These data modeling decisions were made based off the answers to these questions.
In this game, there is a different page presented to the player for their inventory for weapons and another page for armor. When the player opens their inventory, weapons are shown first because we want that page to load extremely fast, while subsequent inventory pages can load after that. Since each of these item types can be quite large as the player acquires more in-game items, we decided that each inventory page would be its own item in the playerâs item collection in the database.
The following section talks more about how you can interact with item collections through the Query
operation.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4