Searching inside embedded documents

Searching inside embedded documents is exactly like searching inside hashes. This seems to make sense because MongoDB saves every document as a hash.

Note

Embedded documents are sometimes also called nested documents in discussion.

The following is an example of an embedded document:

{
"_id" : ObjectId("6234a68bfed0eb0beabcd234"),
"name" : "The Adventures of Sindbad",
"category" : {
"_id" : ObjectId("5ad6f68bfed0eb0be1231213"),
"name" : "Adventure",
}
}

To fetch the category object it's exactly the same way as searching inside a hash:

> db.books.find( { "category.name" : "Adventure" }

And just like that, searching inside arrays, hashes, and embedded documents have almost the same syntax!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.23.167