Searching inside hashes

Just like arrays, we also want to search inside hashes. Searching inside hashes involves keys and values. Let's assume that the book object looks as follows (that is, a hash instead of an array):

{
categories: {
'drama': 1,
'thriller': 2
},
}

We can search for all books that have the drama set as 1:

> db.books.find({ "categories.drama" : 1 })

Notice that we access hash fields just like standard JSON object access.

Note

It's interesting to note that the criteria for searching in hashes and arrays is the same in most cases.

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

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