S
S
SimBioT192017-04-04 14:54:12
PHP
SimBioT19, 2017-04-04 14:54:12

Why doesn't $in operator for subarray work in mongodb?

Hey!
Maybe the question is stupid, but I can’t understand why with the simplest document:

{
"_id": "...",
"data": {
           "id": "1",
           "field": "..."
         }
}

I make a request
$mongo->collection->find( ['data.id' => ['$in' => [1, 2,3] ] ]);

But it doesn't find anything for me.
How to find documents using $in for nested array?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2017-04-04
@SimBioT19

Haven't worked with monga for a long time, but try -['data.$.id' => ['$in' => [1, 2,3] ] ]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question