0% found this document useful (0 votes)
25 views3 pages

MongoDB Notes With Operators

This document provides a comprehensive overview of various MongoDB commands and matched operators, including basic find operations, limit/skip/sort functionalities, comparison and logical operators, and update/delete commands. It also covers element and expression operators, dot notation for embedded fields, and examples of counting and retrieving single results. The document serves as a reference for performing CRUD operations in MongoDB.

Uploaded by

amorvignesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views3 pages

MongoDB Notes With Operators

This document provides a comprehensive overview of various MongoDB commands and matched operators, including basic find operations, limit/skip/sort functionalities, comparison and logical operators, and update/delete commands. It also covers element and expression operators, dot notation for embedded fields, and examples of counting and retrieving single results. The document serves as a reference for performing CRUD operations in MongoDB.

Uploaded by

amorvignesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MongoDB Notes - Commands & Matched Operators

Basic Find (No operator)

[Link]()
[Link]({name: "vicky"})
[Link]({name: "vicky"}, {name: 1, age: 1})
[Link]({name: "vicky"}, {name: 1, age: 1, _id: 0})
[Link]({name: "vicky"}, {age: 0})

Limit / Skip / Sort (Command options)

[Link]().limit(2)
[Link]().sort({name: 1}).limit(3)
[Link]().sort({name: -1}).limit(3)
[Link]().sort({age: -1, name: -1}).limit(3)
[Link]().sort({age: 1, name: 1}).limit(3)
[Link]().skip(1).limit(3)

Comparison Operators

[Link]({name: {$eq: "vicky"}}) // $eq


[Link]({name: {$ne: "vicky"}}) // $ne
[Link]({age: {$gt: 24}}) // $gt
[Link]({age: {$gte: 24}}) // $gte
[Link]({age: {$lt: 24}}) // $lt
[Link]({age: {$lte: 24}}) // $lte
[Link]({name: {$in: ["vicky","amor"]}}) // $in
[Link]({name: {$nin: ["vicky","amor"]}}) // $nin

Element Operators

[Link]({skill: {$exists: true}}) // $exists


[Link]({skill: {$exists: false}}) // $exists

Range (Combined Comparison)

[Link]({age: {$gte: 20, $lte: 30}}) // $gte + $lte


MongoDB Notes - Commands & Matched Operators

Logical Operators

[Link]({$and: [{age: {$gt: 24}}, {city: "chennai"}]}) // $and


[Link]({$or: [{age: {$gt: 24}}, {city: "chennai"}]}) // $or
[Link]({age: {$not: {$gte: 20}}}) // $not

Expression Operators

[Link]({$expr: {$gt: ["$salary", "$bonus"]}}) // $expr

Dot Notation (Embedded Fields)

[Link]({"[Link]": 609108})

Count / Single Result

[Link]({age: {$gt: 20}})


[Link]({age: {$gt: 20}})

Update Operators

[Link]({_id: ObjectId('...')}, {$set: {name: "amor*vicky"}}) // $set


[Link]({name: "city"}, {$set: {name: "vicky"}}) // $set
[Link]({name: "amor*vicky"}, {$inc: {age: 1}}) // $inc
[Link]({name: "amorvicky"}, {$rename: {ages: "age"}}) // $rename
[Link]({name: "amorvicky"}, {$push: {skill: "net"}}) // $push
[Link]({name: "amorvicky"}, {$pull: {skill: ["node", "net"]}})// $pull
[Link]({name: "amorvicky"}, {$unset: {skill: ""}}) // $unset
[Link]({amorvicky: {$exists: true}}, {$unset: {amorvicky: ""}}) // $unset,
$exists

Replace Operator

[Link](
{name: "amorvicky"},
MongoDB Notes - Commands & Matched Operators

{name: "amorvicky", age: 25, address: "koothiyam pettai", contectno: 7010901510,


skill: ["money","game","play outdoor"]}
)

Delete Operators

[Link]({name: "amorvicky"})
[Link]({contectno: {$exists: true}}) // $exists

You might also like