Basically, MongoDB is an Object-Oriented Database where we not only use MongoDB Query to fetch the results, we can also use this JavaScript like expressions to operate the data from database. We can use some basic operations like ‘&&’, ‘>’, ‘!=’, etc. below is the example for both JavaScript and MongoDB Querying.
Example: trying to get the results with style number greater than 600000 and style description not equal to MM GRAPHIC PO HOOD.
Query using JavaScript expression:
db.styles.find(
"this.style.number
> 600000 && this.style.description !='MM GRAPHIC PO HOOD'"
)
Query using
MongoDB Syntax:
db.style.find(
{
"style.number":{$gt:"600000"},
"style.description":{$ne:"MM
GRAPHIC PO HOOD"}}
)
Performance
matters:
To get the best
performance, use the Mongo Query rather than javaScript expression to fetch the
results.