How to get MongoDB documents using array field selection

My data structure is as follows:

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

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

Is this possible in Meteor?

+4
source share
1 answer

I provide a mongo request, I don’t think it will be difficult for you to send it via Meteor (which I do not use).

So try this simple $ or

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

Source: https://habr.com/ru/post/1625613/


All Articles