dynogels
dynogels copied to clipboard
Unable to filter on array elements
I am new to DynamoDb. I am trying to access an object inside the array:
Created a new item in a table-
survey.create({
survey_name: 'Cycle',
description: 'Describe me',
test:[{
title:'hello1'
},{
title:'hello2'
}]
}, function (err, survey) {
if(err){
console.log(err)
}else{
console.log('created', survey.get('survey_name'));
}
});
I am not to able to fetch "test[n].title", getting 0 results.
survey.query('Cycle')
.filter('test.title').equals('hello2') //Tried it with test[0].title also
.exec((err,data)=>{
if(err){
console.log(err);
}
else{
console.log(data);
}
});
Also, I want to retrieve a part(json) of the item of a table ie. 'test' if its possible
It fails because test[0].title
is equal to 'hello1'
, not 'hello2'
.
Use .attributes()
to limit the attributes that are fetched from the database. See the query documentation.
Tried with test[1].title also. Getting 0 results.
I am facing problem in accesing nested properties.
@clarkie Reading this section of the code, it seems like we don't correctly handle array access expressions. As in the above example, "test[0].title"
would be built as the equivalent of the JavaScript indexing expression object["test[0]"].title
, which obviously doesn't work right.
@abhinav-juneja Can you confirm that filtering on nested objects (without arrays) works correctly?
Filtering on nested objects works as expected.