How to use greater than queries in mongodb

Posted in Tutorials

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

In this tutorial, we will query mongodb for states where the high temperature is greater than 100 and less than 110 Fahrenheit.

The data that we are querying from in MongoLab looks  like this in the firstdb database in the highlowtemp collection …

mongolab database

mongolab database

We continue from last tutorial here but changing things slightly…

greater than comparison

greater than comparison

In our query object, we use the ‘$gt’ and ‘$lt’ operator.   Passing the query object in our find() method, we call the each() method and output the returned records.

Note also how we used dot-notion in “high.fahrenheit” to access a field nested within the data object.