
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
327 Views
Let us create a collection with documents −> db.demo313.insertOne({"_id":100, "details":[{"Name":"Chris", "Age":24}]}); { "acknowledged" : true, "insertedId" : 100 } > db.demo313.insertOne({"_id":101, "details":[{"Name":"David", "Age":22}]}); { "acknowledged" : true, "insertedId" : 101 } > db.demo313.insertOne({"_id":102, "details":[{"Name":"Mike", "Age":25}]}); { "acknowledged" : true, "insertedId" : 102 }Display all documents from a collection with the ... Read More

AmitDiwan
203 Views
To update partial number of documents, set multi to true. Let us create a collection with documents −> db.demo312.insertOne({"FirstName":"Robert"}); { "acknowledged" : true, "insertedId" : ObjectId("5e50ce16f8647eb59e56204a") } > db.demo312.insertOne({"FirstName":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5e50ce19f8647eb59e56204b") } > db.demo312.insertOne({"FirstName":"Robert"}); { "acknowledged" : true, "insertedId" ... Read More

AmitDiwan
288 Views
For faster queries, create an index. To get the count, use count(). Let us create a collection with documents −> db.demo311.ensureIndex({"Name":1}); { "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } > db.demo311.insertOne({"Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e50cd01f8647eb59e562044") ... Read More

AmitDiwan
405 Views
To push document into an array, use $push along with update(). Let us create a collection with documents −>db.demo310.insertOne({"Name":"Chris", "details":[{"Id":101, "Subject":"MySQL"}, {"Id":102, "Subject":"MongoDB"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e50cabdf8647eb59e562043") }Display all documents from a collection with the help of find() method −> db.demo310.find();This will produce the following ... Read More

AmitDiwan
202 Views
To remove, use remove() in MongoDB. Let us create a collection with documents −> db.demo309.insertOne({ "details":[ { "Name":"Chris" }, { "Name":"David" }, { "Name":"Adam" } ] } ); { "acknowledged" : true, "insertedId" : ObjectId("5e4eb71af8647eb59e562040") } > db.demo309.insertOne({ "details":[ { "Name":"David" }, { "Name":"Mike" }, { "Name":"Bob" } ... Read More

AmitDiwan
668 Views
To retried a subset of fields, use dot notation in find(). Let us create a collection with documents −> db.demo307.insertOne({ ... "CleintId":101, ... "ClientDetails":{"ClientFirstName":"Chris", "Age":34}, ... "ClientCountryName":"US" ...} ...); { "acknowledged" : true, "insertedId" : ObjectId("5e4eab88f8647eb59e56203c") } > db.demo307.insertOne({ ... "CleintId":102, ... "ClientDetails":{"ClientFirstName":"David", ... Read More

AmitDiwan
355 Views
To fetch documents, use find() in MongoDB. With that, to format the resultant documents, use pretty().Let us create a collection with documents −> db.demo306.insertOne({"Name":"Robert", "Age":21}); { "acknowledged" : true, "insertedId" : ObjectId("5e4ea7c6f8647eb59e562038") } > db.demo306.insertOne({"Name":"David", "Age":23}); { "acknowledged" : true, "insertedId" : ObjectId("5e4ea7cdf8647eb59e562039") } > db.demo306.insertOne({"Name":"Mike", ... Read More

AmitDiwan
1K+ Views
To get the child of a collection in MongoDB, use find(). Let us create a collection with documents −> db.demo305.insertOne( ... { ... _id: 101, ... FirstName : 'Chris', ... details : { ... "0":"102", ... ... Read More

AmitDiwan
124 Views
Use $or operator to fetch values and to format the result, use “pretty()”. Let us create a collection with documents −> db.demo304.insertOne({"StudentName":"Chris", "StudentAge":23}); { "acknowledged" : true, "insertedId" : ObjectId("5e4ea3ccf8647eb59e562034") } > db.demo304.insertOne({"StudentName":"David", "StudentAge":22}); { "acknowledged" : true, "insertedId" : ObjectId("5e4ea3d7f8647eb59e562035") } > db.demo304.insertOne({"StudentName":"Mike", "StudentAge":24}); { ... Read More

AmitDiwan
320 Views
For distinct values, use distinct(). Let us create a collection with documents −> db.demo303.insertOne({FirstName:"Chris", LastName:"Brown"}); { "acknowledged" : true, "insertedId" : ObjectId("5e4ea0f6f8647eb59e56202f") } > db.demo303.insertOne({FirstName:"John", LastName:"Doe"}); { "acknowledged" : true, "insertedId" : ObjectId("5e4ea104f8647eb59e562030") } > db.demo303.insertOne({FirstName:"Chris", LastName:"Smith"}); { "acknowledged" : true, "insertedId" : ObjectId("5e4ea10df8647eb59e562031") ... Read More