
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
152 Views
For this, simply use find(). Set the fields you don’t want to select to 0. Let us create a collection with documents −> db.demo269.insertOne({StudentId:101, StudentSubject:"MySQL"}); { "acknowledged" : true, "insertedId" : ObjectId("5e481caa1627c0c63e7dbab4") } > db.demo269.insertOne({StudentId:102, StudentSubject:"Java"}); { "acknowledged" : true, "insertedId" : ObjectId("5e481cb11627c0c63e7dbab5") } > db.demo269.insertOne({StudentId:103, ... Read More

AmitDiwan
215 Views
To search a value, simply use $where in MongoDB. Let us create a collection with documents −> db.demo268.insertOne( ... { ... "details" : { ... "101" : "John", ... "1001" : "Bob" ... } ... } ... Read More

AmitDiwan
245 Views
For descending order, use -1, which specifies sorting order for sort(), Let us create a collection with documents −> db.demo267.insertOne({id:100, "Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e4811951627c0c63e7dbaab") } > db.demo267.insertOne({id:100, "Name":"Adam"}); { "acknowledged" : true, "insertedId" : ObjectId("5e48119e1627c0c63e7dbaac") } > db.demo267.insertOne({id:100, "Name":"David"}); { "acknowledged" ... Read More

AmitDiwan
267 Views
The $not operator won’t invert a complex expression. Therefore, use $and or $or with $ne operator.Let us create a collection with documents −> db.demo266.insertOne({"active1":true, "active2":false}); { "acknowledged" : true, "insertedId" : ObjectId("5e480f4b1627c0c63e7dbaa7") } > db.demo266.insertOne({"active1":true, "active2":true}); { "acknowledged" : true, "insertedId" : ObjectId("5e480f501627c0c63e7dbaa8") } > db.demo266.insertOne({"active1":false, ... Read More

AmitDiwan
251 Views
To update only certain fields, use $set. Let us create a collection with documents −> db.demo265.insertOne({"id":101, "Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e480d781627c0c63e7dbaa4") } > db.demo265.insertOne({"id":102, "Name":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5e480d7d1627c0c63e7dbaa5") } > db.demo265.insertOne({"id":103, "Name":"David"}); { "acknowledged" : true, "insertedId" ... Read More

AmitDiwan
472 Views
To get the count and top users, use $group along with aggregate() . Let us create a collection with documents −> db.demo264.insertOne({"Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e47ed441627c0c63e7dba9e") } > db.demo264.insertOne({"Name":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e47ed471627c0c63e7dba9f") } > db.demo264.insertOne({"Name":"Chris"}); { "acknowledged" : ... Read More

AmitDiwan
214 Views
To skip documents in MongoDB, use skip(). Let us create a collection with documents −> db.demo263.insertOne({_id:100}); { "acknowledged" : true, "insertedId" : 100 } > db.demo263.insertOne({_id:200}); { "acknowledged" : true, "insertedId" : 200 } > db.demo263.insertOne({_id:300}); { "acknowledged" : true, "insertedId" : 300 }Display all documents from a collection with ... Read More

AmitDiwan
261 Views
To invert result i.e. opposite of $and operation, use $OR along with $ne. Let us first create a collection with documents −> db.demo4.insert({uid:1, "Name":"Chris", "Age":22}); WriteResult({ "nInserted" : 1 }) > db.demo4.insert({uid:2, "Name":"David", "Age":21}); WriteResult({ "nInserted" : 1 }) > db.demo4.insert({uid:3, "Name":"Bob", "Age":23}); WriteResult({ "nInserted" : 1 }) > db.demo4.insert({uid:1, ... Read More

AmitDiwan
255 Views
To add only a single value to array, use $push. Let us first create a collection with documents −> db.demo3.insertOne( ... { ... "Information" : { ... "Of" : { ... "StudentCode" : "STUDENT101", ... ... Read More

AmitDiwan
301 Views
To modify a sequence, use findAndModify(). Let us create a collection with documents −> db.demo261.insertOne({_id:100, Name:"Chris"}); { "acknowledged" : true, "insertedId" : 100 }Display all documents from a collection with the help of find() method −> db.demo261.find();This will produce the following output −{ "_id" : 100, "Name" : "Chris" }Following ... Read More