1

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

1 Answers1

1

Querying DynamoDB using filters requires the key you are filtering on to be the top level key. You cannot filter using a nested object key.

Asdfg
  • 11,362
  • 24
  • 98
  • 175
  • Is there any other property or function, with which i can query nested property (ie. test[1].title or test[0].title) ? – Abhinav Juneja Jan 30 '18 at 00:29
  • Basically, i want to filter out sub document ie test object.. In mongodb.. it can be achieved by using this: db.survey.findOne({ test: { $elemMatch : { title: 'hello2' }} }).. expected result is : survey_name: 'Cycle', description: 'Describe me', test:[{ title:'hello1' }]  Is it possible in dynamodb? – Abhinav Juneja Jan 30 '18 at 00:50