Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to filter on array elements #135

Open
abhinav-juneja opened this issue Jan 29, 2018 · 5 comments
Open

Unable to filter on array elements #135

abhinav-juneja opened this issue Jan 29, 2018 · 5 comments
Assignees
Labels

Comments

@abhinav-juneja
Copy link

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

@cdhowie cdhowie self-assigned this Jan 29, 2018
@cdhowie
Copy link
Collaborator

cdhowie commented Jan 29, 2018

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 cdhowie closed this as completed Jan 29, 2018
@abhinav-juneja
Copy link
Author

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

@abhinav-juneja
Copy link
Author

I am facing problem in accesing nested properties.

@cdhowie cdhowie reopened this Jan 30, 2018
@cdhowie
Copy link
Collaborator

cdhowie commented Jan 30, 2018

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

@abhinav-juneja
Copy link
Author

Filtering on nested objects works as expected.

@cdhowie cdhowie added bug and removed question labels Jan 31, 2018
@cdhowie cdhowie changed the title unable to access nested objects and array of objects Unable to filter on array elements Jan 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants