Answer the question
In order to leave comments, you need to log in
MongoDB: how to compose a select query on two parameters of a multidimensional array?
There is a collection:
{name: 'Name 1', params: [{id : 'Sale', value : 'No'}, {id: 'Warranty', value: 'Yes'}]}
{name: 'Name 2' , params: [{id : 'Sale', value : 'Yes'}, {id: 'Warranty', value: 'No'}]}
{name: 'Name 3', params: [{id : 'Sale' , value : 'Yes'}, {id: 'Warranty', value: 'Yes'}]}
{name: 'Name 4', params: [{id : 'Sale', value : 'No'}, {id : 'Guarantee', value: 'Yes'}]}
How can I make a query so that I can select for example everything, where Sale = Yes
Do this {'$and' : [{'params.id' : 'Sale'}, {'params.value' : 'Yes'}]}
But the selection also includes those records where Sale = No, and Warranty = Yes
PS: Params nesting can be any
Answer the question
In order to leave comments, you need to log in
{ params: { $elemMatch: { id : "Распродажа", value : "Да" } } }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question