dynamodb-document-js-sdk: IN operator won't work with array variable in FilterExpression?
First off, great library. Thank you!
I’ve got this array: var client_ids = ["data_8109"]; and I’m putting it into the FilterExpression function with an IN operator, but the query is not locating the record. If I don’t use the array variable and hardcode the single client_id in, it shows up. Is my syntax missing something?
var params = {
TableName: 'apps',
IndexName: 'state-index',
KeyConditions: [
DynamoDBInstance.Condition("state", "EQ", "active")
],
FilterExpression: "#a IN (:client_ids)",
ExpressionAttributeNames: {
"#a": "client_id"
},
ExpressionAttributeValues: {
":client_ids": client_ids
}
};
console.time('DynamoDB: ShowApp By Client IDs');
DynamoDBInstance.query(params, function(error, response) {
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 20 (2 by maintainers)
Has this been added yet? I’m having a difficult time understanding why this functionality wouldn’t be in a db half way through 2017. I think this is a pretty common use case.
Hi, i made a simple workaround for the
INoperator with arraysthis method will return the
FilterExpressionandExpressionAttributeValuesfor an array and you can extend it with some edits to include more filter options.Hope it helps anyone stuck in handling arrays with
INoperator.Hi I want to query that contains a List Map object in db the item is in the format: { id:‘1323234’, item:[ {text:‘abcd’,author:‘x’}, {text:‘efgh’,author:‘y’} ] created_at:‘somedate’
}
i want to make a search where item text matches ‘cd’
Can you please help me out?
You can use filter expressions to do server side filtering before the scan/query result comes back to your client. For example, if the GroupOfUsers attribute in your items is a StringSet, the filter expression contains(GroupOfUsers, :user) combined with ExpressionAttributeValues={“:user”:“xyz”} will only return items that have xyz in the GroupOfUsers attribute. This may require scanning a large part of the table, depending on your use case, so you might want to consider denormalizing schema so that you can use the Query operation to lessen the number of items you need to read.
@nirmalgoswami thanks man for your quick response.