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.
Accessing embedded/nested documents – In MongoDB, you can access the fields of nested/embedded documents of the collection using dot notation and when you are using dot notation, then the field and the nested field must be inside the quotation marks.
To clone a document, hover over the desired document and click the Clone button. When you click the Clone button, Compass opens the document insertion dialog with the same schema and values as the cloned document. You can edit any of these fields and values before you insert the new document.
An embedded, or nested, MongoDB Document is a normal document that's nested inside another document within a MongoDB collection. Embedded documents are particularly useful when a one-to-many relationship exists between documents.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With