From the course: MongoDB Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Comparison operators

Comparison operators

- [Instructor] Let's talk about using comparison operators. There are eight comparison operators that you can use in MongoDB. The first six are the common ones you'd expect, $eq for equal, $gt for greater than, $gte for greater than or equal, $lt for less than, $lte for less than or equal and $ne for not equal. Let's try these out on the terminal. All right, again, we're going to be using the sample data database. And on this, we are going to be using the inventory directory. So just to remind ourselves, we're going to look at one document from this collection so that we know the structure. So this contains information about cars. All right. Now, if you look into this document, there's a variations array that contains different variations of the car in different colors. Each of these color variations has a quantity assigned to it. So that's how many cars with that color are in stock. So if we wanted to search for…

Contents