Your Hash key (primary sort) must be unique (unless you have a range, as indicated by others). A.
In your case, you must have a secondary index to query your table.
| ID | DataID | Created | Data | |------+--------+---------+------| | hash | xxxxx | 1234567 | blah |
Your hash key is the identifier Your secondary index is defined as: DataID-Created-index (the name that DynamoDB will use)
Then you can make a request like this:
var params = { TableName: "Table", IndexName: "DataID-Created-index", KeyConditionExpression: "DataID = :v_ID AND Created > :v_created", ExpressionAttributeValues: {":v_ID": {S: "some_id"}, ":v_created": {N: "timestamp"} }, ProjectionExpression: "ID, DataID, Created, Data" }; ddb.query(params, function(err, data) { if (err) console.log(err); else { data.Items.sort(function(a, b) { return parseFloat(a.Created.N) - parseFloat(b.Created.N); });
Essentially, your request looks like this:
SELECT * FROM TABLE WHERE DataID = "some_id" AND Created > timestamp;
The secondary index will increase the required read / write units, so you need to consider this. This is still much better than doing a scan, which will be expensive to read and in time (and limited to 100 points that I consider).
This may not be the best way to do this, but for those used for RD (I'm also used to SQL), this is the fastest way to get performance. Since there are no restrictions on the scheme, you can hack something that works, and once you have the bandwidth to work in the most efficient way, you can make a difference.
ET Jul 02 '15 at 18:53 2015-07-02 18:53
source share