E
E
Evgeny Kuznetsov2015-07-09 20:24:03
MongoDB
Evgeny Kuznetsov, 2015-07-09 20:24:03

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

1 answer(s)
I
Ilya Shatokhin, 2015-07-09
@evgentus

{ params: { $elemMatch: { id : "Распродажа", value : "Да" } } }

Here with explanations

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question