Introduction to MongoDB finding Documents Part 2

Rama Sagar
Posted by in NoSql category on for Beginner level | Points: 250 | Views : 15646 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.
Read Introduction to Mongo DB finding Documents before this article.


In this article we will learn how to find documents in MongoDB with a practical example

Previous articles have provided an introduction to MongoDB 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 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



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

In previous article we have seen the options of querying using different operators. In this part 2 we will see few more…

Our animal document contains a tag field and the tags field contains an array of tags

So let us see how to match among those…

We can notice that we are finding the tag field of tag which matches cute

Note:-this is strictly quality and it also case sensitive

Now let’s find animals who are cute or in the ocean we will get some animals which are cute and some which are in ocean but not necessarily both of them as shown below ….

Now if we want to insist that there would be both ocean and cute tagged we can issue the following command by using all operator as shown below…

If we want to find the document which are none in the tags we can use nin operator as shown below


In this article we have seen the different ways of finding documents..In coming articles we can see how to use cursor operations 


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)