Introduction to Mongo DB finding Documents

Rama Sagar
Posted by in NoSql category on for Beginner level | Points: 250 | Views : 14370 red flag

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

·         Introduction to Mongo Database

·         Introduction to Mongo DB setting up the server

·         Introduction to Mongo DB Command Line options

·         Introduction to Mongo DB install as a service

·         Introduction to Mongo DB Mongo Shell

·         Introduction to Mongo DB Replica set

·         Introduction to Mongo DB Storing Data 

·         Introduction to Mongo DB Storing Data Part 2

·         Introduction to Mongo DB Updating document

·        Introduction to Mongo DB Updating document Part2       



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 operations


Finding Documents


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 articles.

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 than

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...


Page copy protected against web site content infringement by Copyscape

About the Author

Rama Sagar
Full Name: RamaSagar Pulidindi
Member Level: Silver
Member Status: Member,MVP
Member Since: 12/30/2012 1:51:40 AM
Country: India
A Software Profesional working in Microsoft .NET technologies since year 2008, and I work for Dake ACE. I am passionate about .NET technology and love to contribute to the .NET community at Dot Net Funda

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)