D
D
Denis Denis2016-02-02 07:41:42
MongoDB
Denis Denis, 2016-02-02 07:41:42

How to do a lookup in a Mongo nested array?

There is a collection 'users' with 1 document
db.users.find() returns ()

{                                   
        "_id" : "L7Bo6u6Xy7KyXLvBR",                          
        "username" : "user",        
        "emails" : [                
                {                   
                        "address" : '[email protected]'
                }                   
        ]                           
}

like this
db.users.find({ 'emails':{'address': '[email protected]' }})

does not find, although in my understanding it should.
Or is searching in a nested array different from searching in a nested object?
Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rostislav Grigoriev, 2016-02-02
@golovewkin

db.users.find({ 'emails':{ $elemMatch: {'address': '[email protected]'}}})

B
Businka76, 2020-06-07
@Businka76

db.users.find({ "emails.address": "[email protected]" })

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question