MongoDB - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

MongoDB Query

MongoDB Query

shape Description

A MongoDB Query in the database consists of an activity statement query or select statement query. An activity statement query will appeal for extra applications for the information, for example, inserting, updating, or deleting. A select statement query is basically an information for recovering a query.

Find()

shape Description

In MongoDB Query, the find() method is used to query the information inside the collection of mongoDB database.

shape Syntax

The syntax for MongoDB Query find() method is as follows:
>db.collection_name.find()

Pretty()

shape Description

The pretty() method will display the output in a significant and efficient manner.

shape Syntax

The syntax for MongoDB Query pretty() method is as follows:
>db.mycol.find().pretty()

shape Examples

By viewing the below example, one can easily understand the concept of pretty() method in the mongoDB database. [c]MongoDB shell version: 3.2.7 connecting to: test > use testdb switched to db testdb > db.testdb.insert({"name": "James"}) WriteResult({ "nInserted" : 1 }) > db.testdb.find().pretty() { "_id" : ObjectId("577e15d4e24946f4cb1d93a1"), "name" : "James" } [/c] Here in the above example, a document by name james is successfully inserted into the mongoDB database.

MongoDB Syntaxs

shape Description

The following are the basic syntax's for mongoDB databases.
Operation Syntax Example
Equality {<key>:<value>} db.mycol.find({"by":"itoolsinfo.com"}).pretty()
Less then equal {<key>:{$lte:<value>}} db.mycol.find({"likes":{$lte:50}}).pretty()
Less then {<key>:{$lt:<value>}} db.mycol.find({"like":{$lt:50}}).pretty()
Greater then equal {<key>:{$gte:<value>}} db.mycol.find({"likes":{$gte:50}}).pretty()
Greater then {<key>:{$gt:<value>}} db.mycol.find({"likes":{$gt:50}}).pretty()"
Not equal {<key>:{$ne:<value>}} db.mycol.find({"likes":{$ne:50}}).pretty()

Summary

shape Key Points

  • MongoDB Query Document - A query is a collection of variables of homogeneous data type.
  • Find() - Is used to query the information inside the collections.
  • Pretty() - This method will display the output in proper manner.