dynogels icon indicating copy to clipboard operation
dynogels copied to clipboard

Unable to filter on array elements

Open abhinav-juneja opened this issue 6 years ago • 5 comments

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

abhinav-juneja avatar Jan 29 '18 17:01 abhinav-juneja

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.

cdhowie avatar Jan 29 '18 18:01 cdhowie

Tried with test[1].title also. Getting 0 results.

abhinav-juneja avatar Jan 30 '18 00:01 abhinav-juneja

I am facing problem in accesing nested properties.

abhinav-juneja avatar Jan 30 '18 00:01 abhinav-juneja

@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?

cdhowie avatar Jan 30 '18 02:01 cdhowie

Filtering on nested objects works as expected.

abhinav-juneja avatar Jan 30 '18 05:01 abhinav-juneja