I'm starting to learn Dynamodb here, and currently trying to do a search on my table where PK is the partition key and SK is the range key. PK contains an email address, whereas SK contains value like AB_STATE
, BC_STATE
, MY_STATE
. So I want to search in the SK where the value starts with MY_
but I'm not entirely sure how to do it using .get()
function.
Here's my query Seller.get({ "PK": "imin@cats.com", "SK" : "MY" })
which obviously isn't doing what I wants.
I am aware that I maybe can use filter like below, but I read in many places that using filter is not recommended (?)
var filter = new dynamoose.Condition().where("PK").eq(email).filter("SK").beginsWith("MY_");
var premiseProfile = await Seller.query(filter).exec()
Below is the schema for my Seller table
const schema = new dynamoose.Schema({
PK: {
type: String,
hashKey: true,
},
SK: {
type: String,
rangeKey: true,
},
"firstName": String,
"lastName": String,
"gender": {
"type": Number,
"default": 0
},
}, {
"saveUnknown": true,
"timestamps": true
});