简体   繁体   中英

How to retrieve MongoDB documents via selection by array field

My data structure is as follows:

{
    _id: ...,
    topLevelField: ...,
    items: [{
        field1: ...,
        field2: ...
    }]
}

I want to query all documents where topLevelField = 'X' OR items array contains an object with field2 = 'Y' .

Is this possible in Meteor?

I'm providing the mongo query, I don't think it'll be difficult for you to send it via Meteor (which I don't use).

So try this simple $or query

{ $or: [ { 'topLevelField' : 'X' }, { 'items.field2' : 'Y' } ] } 

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