
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
743 Views
To aggregate multiple result, use $group in MongoDB. Let us create a collection with documents −> db.demo765.insertOne( ... ... { ... Name:"John", ... "Category":"ComputerScience", ... "SubjectName":"MongoDB", ... "Marks":75 ... } ... ); { "acknowledged" : ... Read More

AmitDiwan
791 Views
Use $ne to check for not null. Let us create a collection with documents −> db.demo764.insertOne({"LoginUserName":"Chris", "LoginPassword":"Chris_12"}); { "acknowledged" : true, "insertedId" : ObjectId("5eb04ee55637cd592b2a4afc") } > db.demo764.insertOne({"LoginUserName":"Chris", "LoginPassword":null}); { "acknowledged" : true, "insertedId" : ObjectId("5eb04eee5637cd592b2a4afd") } > db.demo764.insertOne({"LoginUserName":"Chris", "LoginPassword":""}); { "acknowledged" : true, "insertedId" ... Read More

AmitDiwan
1K+ Views
To query on an array of objects for nested documents, use find(). Let us create a collection with documents −> db.demo763.insertOne( ... { ... _id:1, ... CountryName:"US", ... "studentInformation": [ ... { ... ... Read More

AmitDiwan
1K+ Views
For this, use $project along with aggregate(). The $project in aggregation passes along the documents with the requested fields to the next stage in the pipeline.Let us create a collection with documents −> db.demo762.insertOne({ ... "_id" : { ... "userId":101, ... "userName":"Chris" ... ... Read More

AmitDiwan
650 Views
To fetch a specific value from an array, use aggregate() along with $project. Let us create a collection with documents −> db.demo761.insertOne( ... { ... "details": [ ... { ... "student": { ... ... Read More

AmitDiwan
583 Views
To update many documents with a single query, use bulkWrite() in MongoDB. Let us create a collection with documents −> db.demo760.insertOne({id:1, details:{Value1:100, Value2:50}}); { "acknowledged" : true, "insertedId" : ObjectId("5eb0309f5637cd592b2a4aee") } > db.demo760.insertOne({id:2, details:{Value1:60, Value2:70}}); { "acknowledged" : true, "insertedId" : ObjectId("5eb030a15637cd592b2a4aef") } > db.demo760.insertOne({id:3, details:{Value1:80, ... Read More

AmitDiwan
567 Views
For this, you need to use case insensitive (i). Let us create a collection with documents −> db.demo759.insertOne({SubjectName:"MySQL"}); { "acknowledged" : true, "insertedId" : ObjectId("5eb02ba95637cd592b2a4ae7") } > db.demo759.insertOne({SubjectName:"MongoDB"}); { "acknowledged" : true, "insertedId" : ObjectId("5eb02baa5637cd592b2a4ae8") } > db.demo759.insertOne({SubjectName:"mongodb"}); { "acknowledged" : true, "insertedId" : ... Read More

AmitDiwan
508 Views
For this, you can use $out along with aggregate() and $unwind. Let us create a collection with documents −> db.demo757.insertOne( ... { ... "id": 101, ... "Name": ["John", "Bob", "Chris"] ... } ... ); { "acknowledged" : true, "insertedId" : ... Read More

AmitDiwan
1K+ Views
To check for duplicates in an array, use aggregate() in MongoDB. Let us create a collection with documents −> db.demo756.insertOne({"SubjectName":["MySQL", "MongoDB", "Java"]}); { "acknowledged" : true, "insertedId" : ObjectId("5eb01e0d5637cd592b2a4add") } > db.demo756.insertOne({"SubjectName":["MongoDB", "MySQL", "MongoDB", "C", "C+", "MySQL"]}); { "acknowledged" : true, "insertedId" : ObjectId("5eb01e2b5637cd592b2a4ade") }Display all ... Read More

AmitDiwan
386 Views
To sort, use sort() in MongoDB. Let us create a collection with documents −> db.demo755.insertOne({"Value":10}); { "acknowledged" : true, "insertedId" : ObjectId("5eae9e72a930c785c834e572") } > db.demo755.insertOne({"Value":10.5}); { "acknowledged" : true, "insertedId" : ObjectId("5eae9e75a930c785c834e573") } > db.demo755.insertOne({"Value":9.5}); { "acknowledged" : true, "insertedId" : ObjectId("5eae9e79a930c785c834e574") } > ... Read More