πŸŽ“ Computer Science & Engineering Portal

Master Engineering Disciplines with Structured Notes

Comprehensive academic lecture notes, exam-oriented unit summaries, laboratory manuals, and previous year question papers designed strictly for university students.

πŸ“‘

University Syllabi

AKTU & AICTE aligned semester guidelines.

πŸ“

Exam Question Papers

Previous 5 years solved university papers.

πŸ’‘

Lab Manuals & Viva

Practical codes with outputs & interview Qs.

Core Subjects & Units Hub

Click on any specific unit to immediately view its lecture notes below

Viewing All Lectures

Querying

Querying:

find() Method

To query data from MongoDB collection, you need to use MongoDB's find() method.

Syntax

The basic syntax of find() method is as follows βˆ’

>db.COLLECTION_NAME.find()

find() method will display all the documents in a non-structured way.

pretty() Method

To display the results in a formatted way, you can use pretty() method.

Syntax

>db.COLLECTION_NAME.find().pretty()

findOne() method

Apart from the find() method, there is findOne() method, that returns only one document.

Syntax

>db.COLLECTIONNAME.findOne()

AND in MongoDB

Syntax

To query documents based on the AND condition, you need to use $and keyword. Following is the basic syntax of AND βˆ’

>db.mycol.find({ $and: [ {<key1>:<value1>}, { <key2>:<value2>} ] })

OR in MongoDB

Syntax

To query documents based on the OR condition, you need to use $or keyword. Following is the basic syntax of OR βˆ’

>db.mycol.find(
  {
      $or: [
        {key1: value1}, {key2:value2}
      ]
  }
).pretty()

 

NOR in MongoDB

Syntax

To query documents based on the NOR condition, you need to use the $not keyword. Following is the basic syntax of NOR βˆ’

>db.COLLECTION_NAME.find(
    {
        $nor: [
            {key1: value1}, {key2:value2}
        ]
    }
)

 

NOT in MongoDB

Syntax

To query documents based on the NOT condition, you need to use the $not keyword following is the basic syntax of NOT βˆ’

>db.COLLECTION_NAME.find(
    {
        $NOT: [
            {key1: value1}, {key2:value2}
        ]
    }
).pretty()

Labels: ,

Discussion & Queries (<$I18NNumComments$>):

<$CommentPager$>
<$I18NAtCommentTimeWithPermalink$>, <$I18NCommentAuthorSaid$>

<$BlogCommentBody$>

<$BlogCommentDeleteIcon$>
<$CommentPager$>