To work with more complex queries, we need to have more complex data. So I have a file here called sales dash data dot docs, the extension doesn't matter. But if you look at the file carefully, this is not a JSON array. For example, JSON fields must have double quoted text. And also an array must start with a square bracket. And every JSON object must have a comma.
But this is just a collection of JSON objects, one object per line. So let's import the same into a MongoDB collection. For that, let's issue the command Mongo import. And the DB is test two dB. And the file that we want to use happens to be called sales data dot docs. If you don't mention the collection name, the base name of the file will be used which is sales dash data.
Now I would like to have this as a collection called sales. So I'll say your data collection sales. And when I press enter, you will see that it has imported 286 document. Let's go and have a look into that in the Mongo shell. So we have the sales and the DB dot sales dot find. And then we'll use a pretty format to predefined the same thing, we can see that all the documents are lined up with an automatically generated underscore ID.
Now, it is important to see that we have some numerical fields such as quarter and sales amount, etc. Now let's work on this and execute some more complex queries. Let's say we want to query for our sales collection and get all the sales where the sales amount is more than or equal to $10,000. So the query would look something like DB dot sales dot find and the query is on the sale. Command, so as a sales amount, and then we use a another object and say dollar gt E, and then the amount which is $10,000. itself.
And if you want to prettify the output, let's call the PDF function as well save it. And then I'll say, Mongo less than x zero phi dot j s, and we get a bunch of documents that satisfy that condition.