Given the following data structure;
{
"author": "USERNAME",
"caption": "Caption of video",
"createdAt": 1531260177951,
"id": "03290200-848d-12e8-a1b5-bb9570f524f1", // Current primary key
"s3Bucket": "s3-bucket-name",
"s3Key": "USERNAME/1521260163051.mp4",
"updatedAt": 1531260177951
}
I am trying to write a query, which would be very simple in other languages, such as SQL or MongoDB;
Mongo: db.getCollection("Videos").find({author: {$in: ["USER1", "USER2",..]}}).sort({createdAt: 1})
SQL: SELECT * from videos WHERE author IN ('USER1', USER2',...) SORT BY createdAt
If I add an index on the author field, these queries usually run very quickly.
I have made an index on the author field in dynamoDb, but it appears that there is no way to do anything other than an equal-check on the field. author = :inputAuthor
. Trying to do a author IN (:author1, :author2)
results in an error Invalid operator used in KeyConditionExpression: IN
.
Is DynamoDB the wrong database for me? Or perhaps there are some smart index/query I can utilise to get my query to run quickly?
There are similar questions, like this; How to use βINβ statement in FilterExpression using array - dynamodb, but they all seem to rely on a scan
as far as I can tell, which would be sub-optimal for a big collection.