MongoDB Select Query Document-Programmershelper

0
512
Spread the love

 

MongoDB Select Query

This article will provide step by step basic concept of MongoDB.where you can easily understand the core concept of MongoDB.In a MongoDB<db.Collection.find()>method is used to return all document form collection.this method works same like select query in a relational database.you will find a single document and also find all document from the collection in pretty formate or non-structure.

Prerequisite

It would be better if you have the basic knowledge of RDBMS concept. Actually, you are going to learn a high-performance database so we need some basics of these.You should also read my previous articles.In which I explained.MongoDB inserts document step by step Detail and How can create a Database in MongoDB.

Implementation Section

  • Find method().
  • The find pretty Method().
  • FindOne Method().

Find method()

To select all document from the database the find method is used.find method returns all the documents.the document shown in find method () is non-structure.

The following is basic Syntax-

Output:

The following data is not a formatted way.To overcome this problem we will use a pretty method.

Alt tag MongoDB select query

The find pretty method ()

Using find pretty method().All the result are showing a formatted way. I will show you a simple example with syntax.

The following basic Syntax-

The following data will display in a formatted way

Using Pretty method everything is displayed in the document.

Output:

Alt tag MongoDB select query

FindOne Method()

As the name implies FindOne method returns a single document.if you want to select a single document out of the whole then find one method() is used.

 The following is basic Syntax

you can try this

So searching the whole collection and return one document.

Output:

Alt tag MongDB insert query

Conclusion

I wish I could tell you that a great site of MongoDB.you just understands key element above post-MongoDB select query working.Click here More Detail about how can find method work. I hope you will understand this lecture.Thank you for reading this lecture. Hope you got the idea. please share it.