简体   繁体   中英

query in google datastore as $elemMatch in mongo

I want to filter elements in array fulfilling all the criteria.

like if I have a array

test: [{"organizationName":"strge","familyName":"raju"},{"organizationName":"sand","familyName":"sand"}]

I need query that filters all criteria in same element.I found that its done using $elemMatch in mongo but didnt find similar query in google datastore.

You can think of an equality filter on an array value in Cloud Datastore as a CONTAINS filter.

So if you had an GROUP entity with a members property:

members: [
  { firstName: 'Alice', lastName: 'Smith' }
  { firstName: 'Bob'  , lastName: 'Miller' }
]

you could run:

SELECT * FROM Group WHERE
    members.firstName = 'Alice'
    AND members.lastName = 'Smith'
    AND members.firstName = 'Bob'
    AND members.lastName = 'Miller'

and it would return the above result.

However, this query doesn't check that the firstName and lastName values appear in the same member value. So this query would also return a Group entity that looks like:

members: [
  { firstName: 'Alice',  lastName: 'Jones' }
  { firstName: 'Bob'  ,  lastName: 'Jones' }
  { firstName: 'Chris',  lastName: 'Miller' }
  { firstName: 'Denise', lastName: 'Smith' }
]

To prevent this, you would have to run the first query and then do client-side filtering.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM