From the course: MongoDB Essential Training

Unlock the full course today

Join today to access over 24,000 courses taught by industry experts.

Logical operators

Logical operators

- [Instructor] There are four logical operators that you can use in MongoDB, $and, $or, $nor and $not. Let's look at each one separately. Once again, we're going to be using the sample data database. If you have switched ranges, type in use sample data. All right, now, we're going to be using the inventory collection. So let's just briefly remind ourselves what a document in that collection looks like. Cool, okay, so now, let's look at each operator, starting with $and, and I'm going to just start writing a query to show you what that looks like, and we're going to be using the $and operator. So I'm going to start with that. Cool, so the $and operator takes an array of multiple documents. Each document specifies a condition that documents have to match in order to be in the results set. So in more general terms, the $and operator allows me to query for items that match multiple conditions. So I could, for example…

Contents