MongoDB can be used as a file system, taking advantage of load balancing and data replication features over multiple machines for storing files.
In this article we will learn how to find
documents in mongo dB with a practical example
Previous articles have provided an
introduction to mongo dB and the set up and installation, and few command line
options.You can get them from the following:Introduction to Mongo Database
The objective of the article is to learn how to use the find
command to retrieve documents from Mongo database.
Will take a look at Query criteria, field selection, and cursor
Let’s have a look at the find command signature
It had a query parameter and a projection parameter. The query parameter
is a filter it defines the matching criteria to run against the documents
The Projection parameter defines up those documents to which part
to be returned which is optional.
We will start using the find command which we have seen in previous
If our document is containing huge data and we want to retrieve
only some data from it we can specify a projection to which fields we want to
return as shown below...
Here our animal database contains all the animals from 1 t0 6 so
now let’s find all the animals by issuing a commands shown below…
Here the gt operator means greater than and lt operator means less
Also gte means greater equal and lte less than equal
So we can use these operators to query our database as shown above
We can also specify a range
we can also provide the matching query
Here we can see that we are finding the documents which are 1 and 3 and the same in opposite
In this article we have seen how to query the mongo database and find the documents...