Mongodb – How to get a specific embedded document inside a MongoDB collection?

mongodb

I have a collection Notebook which has embedded array document called Notes. The sample

document looks like as shown below.

{
"_id" : ObjectId("4f7ee46e08403d063ab0b4f9"),
"name" : "MongoDB",
"notes" : [
            {
              "title" : "Hello MongoDB",
              "content" : "Hello MongoDB"
            },
            {
              "title" : "ReplicaSet MongoDB",
              "content" : "ReplicaSet MongoDB"
            }
         ]
}

I want to find out only note which has title "Hello MongoDB". I am not getting what should

be the query. Can anyone help me.

Best Solution

You can do this with mongo version higher 2.2

the query like this:

db.coll.find({ 'notes.title': 'Hello MongoDB' }, {'notes.$': 1});

you can try with $elemMatch like Justin Jenkins