
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
771 Views
For this, use aggregate() in MongoDB. Let us first create a collection with documents −> db.demo126.insertOne( ... { ... "StudentDetails" : { ... "Number" : 1, ... "OtherDetails" : [ ... { ... ... Read More

AmitDiwan
689 Views
To remove a specific element, use $pull. Let us create a collection with documents −> db.demo125.insertOne({"ListOfNames":["John", "Chris", "Bob", "David", "Carol"]}); { "acknowledged" : true, "insertedId" : ObjectId("5e2f304068e7f832db1a7f55") }Display all documents from a collection with the help of find() method −> db.demo125.find().pretty();This will produce the following output −{ ... Read More

AmitDiwan
624 Views
For this, use find() along with update(). Let us create a collection with documents −> db.demo124.insertOne( ... { ... "Name" : "John", ... "Id" : 101, ... "ProjectDetails" : [{ ... "ProjectName1" : "Online Book", ... ... Read More

AmitDiwan
239 Views
Let us create a collection with documents −> db.demo123.insertOne({"ListOfSubject":['MySQL', 'MongoDB', 'Java']}); { "acknowledged" : true, "insertedId" : ObjectId("5e2f24ac140daf4c2a3544b8") } > db.demo123.insertOne({"ListOfSubject":['Python', 'MongoDB', 'C']}); { "acknowledged" : true, "insertedId" : ObjectId("5e2f24cd140daf4c2a3544b9") } > db.demo123.insertOne({"ListOfSubject":['MySQL', 'MongoDB', 'C++']}); { "acknowledged" : true, "insertedId" : ObjectId("5e2f24ce140daf4c2a3544ba") }Display all ... Read More

AmitDiwan
214 Views
To get distinct levels of array field, use $addToSet in MongoDB. Let us create a collection with documents −> db.demo122.insertOne({"ListOfValues":[100, 10]}); { "acknowledged" : true, "insertedId" : ObjectId("5e2f20f1140daf4c2a3544b6") } > db.demo122.insertOne({"ListOfValues":[240, 10]}); { "acknowledged" : true, "insertedId" : ObjectId("5e2f20f7140daf4c2a3544b7") }Display all documents from a collection with ... Read More

AmitDiwan
214 Views
Let us first create a collection with documents −> db.demo121.insertOne( ... { ... "Id" : 101, ... "Details" : [ ... { ... "SubjectId" : "1", ... ... Read More

AmitDiwan
444 Views
For this, use aggregate() in MongoDB. Let us create a collection with documents −> db.demo120.insertOne( ... { ... 'Name': 'Chris', ... 'Subjects': [ 'MySQL', 'MongoDB', 'Java', 'Python' ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e2f11aed8f64a552dae6365") } ... Read More

AmitDiwan
481 Views
To prevent duplicates of multiple fields, use ensureIndex() and set unique:true. Let us create a collection with documents −> db.demo272.ensureIndex({"FirstName":1, "Subject":1}, {unique:true}); { "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } > db.demo272.insertOne({"FirstName":"Chris", "Subject":"MySQL"}); { "acknowledged" : true, "insertedId" ... Read More

AmitDiwan
447 Views
Set a custom variable and use update() along with $inc to increment. Let us create a collection with documents −> db.demo271.insertOne({"Marks":56}); { "acknowledged" : true, "insertedId" : ObjectId("5e4821211627c0c63e7dbabc") } > db.demo271.insertOne({"Marks":78}); { "acknowledged" : true, "insertedId" : ObjectId("5e4821241627c0c63e7dbabd") } > db.demo271.insertOne({"Marks":72}); { "acknowledged" : true, ... Read More

AmitDiwan
735 Views
Let us first create a collection with documents −> db.demo270.insertOne({"ClientName":"Chirs", "Age":34}); { "acknowledged" : true, "insertedId" : ObjectId("5e481e371627c0c63e7dbab8") } > db.demo270.insertOne({"ClientName":"David", "Age":31}); { "acknowledged" : true, "insertedId" : ObjectId("5e481e3d1627c0c63e7dbab9") } > db.demo270.insertOne({"ClientName":"Bob", "Age":31}); { "acknowledged" : true, "insertedId" : ObjectId("5e481e431627c0c63e7dbaba") } > db.demo270.insertOne({"ClientName":"Carol", "Age":36}); ... Read More