
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
AmitDiwan has Published 10744 Articles

AmitDiwan
17K+ Views
To remove an element, update, and use $pull in MongoDB. The $pull operator removes from an existing array all instances of a value or values that match a specified condition.Let us first create a collection with documents −db.demo541.insertOne({"software":{"services":["gmail", "facebook", "yahoo"]}});{ "acknowledged" : true, "insertedId" : ObjectId("5e8ca845ef4dcbee04fbbc11") } > ... Read More

AmitDiwan
468 Views
To select documents grouped by field in MongoDB, use $group along with $project. Let us first create a collection with documents −> db.demo540.insertOne({id:1, "Name":"Chris", "CountryName":"US"});{ "acknowledged" : true, "insertedId" : ObjectId("5e8ca368ef4dcbee04fbbc0e") } > db.demo540.insertOne({id:1, "Name":"Chris", "CountryName":"UK"});{ "acknowledged" : true, "insertedId" : ObjectId("5e8ca36bef4dcbee04fbbc0f") } > db.demo540.insertOne({id:1, "Name":"Chris", "CountryName":"AUS"});{ ... Read More

AmitDiwan
914 Views
To remove subdocument from a document, use $pull along with update(). Let us first create a collection with documents −> db.demo538.insertOne( ... { ... id:101, ... "details": ... { ... anotherDetails: ... [ ... { ... ... Read More

AmitDiwan
221 Views
For sub-documents, use the dot notation. Let us first create a collection with documents −> db.demo537.insertOne({"details":{"SubjectName":"MongoDB"}});{ "acknowledged" : true, "insertedId" : ObjectId("5e8c8a10ef4dcbee04fbbc05") } > db.demo537.insertOne({"details":{"SubjectName":"MySQL"}});{ "acknowledged" : true, "insertedId" : ObjectId("5e8c8a4bef4dcbee04fbbc06") } > db.demo537.insertOne({"details":{"SubjectName":"Java"}});{ "acknowledged" : true, "insertedId" : ObjectId("5e8c8a51ef4dcbee04fbbc07") }Display all documents from ... Read More

AmitDiwan
1K+ Views
For this, use MongoDB aggregate and within that, use $cond. The $cond evaluates a boolean expression to return one of the two specified return expressions.Let us first create a collection with documents −> db.demo536.insertOne({"Name1":"Chris", "Name2":"David"});{ "acknowledged" : true, "insertedId" : ObjectId("5e8c843eef4dcbee04fbbc01") } > db.demo536.insertOne({"Name1":"David", "Name2":"Chris"});{ "acknowledged" : ... Read More

AmitDiwan
494 Views
To delete array values, use $pull in MongoDB. The $pull operator removes from an existing array all instances of a value or values that match a specified condition.Let us first create a collection with documents −> db.demo535.insertOne( ... { ... ... "studentId" : "101", ... "studentName" : "Chris", ... Read More

AmitDiwan
144 Views
For this, use $group in MongoDB IN aggregate(). The $group groups input documents by the specified _id expression and for each distinct grouping, outputs a document. Let us first create a collection with documents −> db.demo534.insertOne({_id:10, "ProductId":100, "ProductName":"Product-1"}); { "acknowledged" : true, "insertedId" : 10 } > db.demo534.insertOne({_id:11, "ProductId":100, "ProductName":"Product-2"}); ... Read More

AmitDiwan
270 Views
The $addToSet operator adds value to an array unless the value is already present, in which case $addToSet does nothing to that array.Let us create a collection with documents −> db.demo533.insertOne({"ProjectName":"Online Hospital Management"});{ "acknowledged" : true, "insertedId" : ObjectId("5e8b4cfaef4dcbee04fbbbfc") } > db.demo533.insertOne({"ProjectName":"Online Library Management"});{ "acknowledged" : true, ... Read More

AmitDiwan
263 Views
For this, use aggregate(). Here, we have considered 3 roles − Admin, Guest, and User. Let us create a collection with documents −> db.demo532.insertOne({"Name":"Chris", "Type":"Admin"});{ "acknowledged" : true, "insertedId" : ObjectId("5e8b4a9def4dcbee04fbbbf9") } > db.demo532.insertOne({"Name":"David", "Type":"Guest"});{ "acknowledged" : true, "insertedId" : ObjectId("5e8b4aa3ef4dcbee04fbbbfa") } > db.demo532.insertOne({"Name":"Bob", "Type":"User"});{ ... Read More

AmitDiwan
425 Views
Yes, use getSiblingDB(). Let us add some documents to the database −> use customer_tracker-990; switched to db customer_tracker-990 > db.demo1.insertOne({"Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea4697ca7e81adc6a0b3954") } > db.demo1.insertOne({"Name":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea46980a7e81adc6a0b3955") } > db.demo1.insertOne({"Name":"Bob"}); { "acknowledged" : true, ... Read More