Anytime you want to have all the sales where the sales amount is between $5,000 and $6,000, obviously, we need to give a more complex query. So let's go and create a new one. And then let's call it as x 06 dot j s. So the query would look something like DB dot sales dot find. And the field that we want to test is sales underscore amount, it is greater than or equals to 5000. And then we also want to specify that it is less than or equals to 6000. So obviously, we have to give multiple conditions at this time.
So the query goes something like this. So DB dot sales dot find and with $1 And which is an array of one or more conditions. And the conditions are themselves objects, where we'll say sales underscore amount greater than or equals to 5000. This is one condition. And then a similar condition where we say sales amount is less than or equal to 6000. So this is going to be LTE.
So we save it, and then run the same. Of course, we also like to do a pretty to make sure that we get the predefined output. Let's execute the same Mongo x 06 dot j s. So you can see that we get a bunch of documents where the sales amount is between five and $6,000. Suppose we want to find out all the sales done in the quarter one or quarter three. So there are two ways to do this one is using a OR operator, or the other one is in in operator. Let's begin with an operator.
So we say DB dot sales dot find with $1, or, and an array of criteria. And each criteria is given as a JSON objects themselves. Since this time, it's just a quarter equals to one or further equals to three, we can just say quarter one, and then another object with a quarter is three. This should fetch the desired results. So we'll also do a pretty print. As you can see, there are a bunch of quarter three documents.
And then if I scroll up, you see quarter one documents and you don't see anything else. So this is one way to do. So and the second method to do the same thing is DB dot sales dot find. And then we simply say, quarter and the operator is dollar in Which takes an array of values that match the quarter, which is one and three in our case. And then as usual, we'll also do a different save it and run the code, we get the similar results. You can also combine multiple criteria, one after the other to give the effect of an AND operation for example, db dot sales dot find, let's say category is equals to beverages.
And then I can give a comma and give another condition that can say for example, quarter dollar in and then I can say one and three. So if I check what is the total number of sales by using Mongo e x 08 dot j s, you will see that there are 22 documents that match this criteria. But if I include or if I remove this condition and then try the same thing once more, you will see that there are more number of products that are 46 documents that match this condition. So giving multiple conditions are going to narrow down the result. So I can also add another condition sales amount greater than or equal to, and then you say for example 5000 would further reduce the number of rows. So this has the same effect as combining all of them using the end operators.