I’m having an issue with DynamoDB.
I have a table with some items that have an owners
property which is of type String Set
.
it would look something like this:
{
"id": "123456",
"name": "myItem",
"owners": "{"987654321", "963852741"}"
}
In my NodeJS
server I’m using dynamoose
to handle the data.
Item Model
const ItemSchema = new Schema({
id: { type: String, hashKey: true },
name: { type: String },
owners: { type: Set, schema: [String] },
});
ItemModel = dynamoose.model('Item', ItemSchema);
Item Controller
async function getIten(req, res) {
// userId = '963852741'
const items = await ItemModel.scan('owners').contains(userId).exec();
// Items equals to `[]`, but it should be the existing item owned by id user (Isn't it?)
res.json({items});
}
PartiQL Editor
If I try this query in the PartiQL
editor, I get what I’m expecting:
SELECT * FROM "myDataBase.items" WHERE CONTAINS(owners, '963852741')
It may be ovious where the issue is, but I’m not being able to find it, or maybe I’m conceptually mistaken, any help is well received, thanks.
Basically what I’m trying to do is to filter a data from a DynamoDB
table, based of one of their properties with a String set
type.
I also tried having a filter, but it didn’t work:
const filter = {
FilterExpression: 'contains(#owners, :owner)',
ExpressionAttributeNames: {
'#owners': 'owners',
},
ExpressionAttributeValues: {
':owner': '963852741',
},
};
ItemModel.scan(filter).exec();
Juan Rojas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.