epilef
epilef

Reputation: 63

Mongodb: findOne by ObjectId inside an array of documents

Sorry for the confusing title, I'm having a hard time describing it.

Basically, here is the document I have stored in my database:

_id: 5fcf596a27365fb14d938afa
vatid:"BE00000011"
name:"ACME Inc"
users: [  {
            _id: 5fcf596a27365fb14d938afb,
            id: 5fcf596a27365fb14d938af9,
            role:"admin"
          }
        ]

Id like to find the object that contains this id: 5fcf596a27365fb14d938af9 inside the users array.

What would the query look like?

Thanks!

Upvotes: 0

Views: 272

Answers (1)

Raymond Reddington
Raymond Reddington

Reputation: 1837

This should do the thing:

{"users.id" : "5fcf596a27365fb14d938af9"}

Upvotes: 1

Related Questions