简体   繁体   中英

Using "OR" and selection by another table model in DynamoDB

I will explain my question with a concrete example. I have single DynamoDB table (for this example). Table is consisting by the two models:

- user: {
firstname
lastname
placeId
typeId
}

// List of favourites for each users
- userFavourites {
userId
favouriteId
favouriteType
}

I would like to effectively find users, by the following rule:

placeId = 'XXX' OR typeId = 'YYY' or user have any favourite with favouriteId: 'ZZZ' and favouriteType: "Dog" OR user have any favourite with favouriteType: "Cat"

I'm using onetable for communication with dynamo: https://doc.onetable.io/start/quick-tour/

Is it possible to do this kind of selection in DynamoDB (with multiple OR and selection by items from another model in same table) and everything together in one rule?

To be efficient with your reads you must do a GetItem or Query which means you have to provide the partition key for the item, that means you cannot do an OR with the native APIs.

You can however do an OR using PartiQL ExecuteStatement where you can say:

SELECT * FROM MYTABLE WHERE PARTITIONKEY IN [1,2,3]

Again this is only useful when it's the partition key.

If you are looking for OR on multiple different values then I suggest perhaps using a more suitable database with more flexible query capability, as to do so with DynamoDB would resul in a full table Scan each time you need a single row/item.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM