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 10740 Articles
AmitDiwan
1K+ Views
To upsert many documents, use UPSERT() with UPDATE(). Let us create a collection with documents −> db.demo425.insertOne({"Name":"Chris", "Age":21}); { "acknowledged" : true, "insertedId" : ObjectId("5e74ee4fbbc41e36cc3cae6c") } > db.demo425.insertOne({"Name":"David", "Age":23}); { "acknowledged" : true, "insertedId" : ObjectId("5e74ee56bbc41e36cc3cae6d") } > db.demo425.insertOne({"Name":"Chris", "Age":21}); { "acknowledged" : true, ... Read More
AmitDiwan
294 Views
To extract a MongoDB document with a specific string, use $match in MongoDB. Let us create a collection with documents −> db.demo424.insert( ... { ... ... "Information" : [ ... { ... id:10, ... ... Read More
AmitDiwan
190 Views
To speed up the $group phase, use $group along with aggregation. Let us see an example and create a collection with documents −> db.demo423.insertOne({"Information":[101, 110, 87, 110, 98, 115, 101, 115, 89, 115]}); { "acknowledged" : true, "insertedId" : ObjectId("5e73a60e9822da45b30346e6") }Display all documents from a collection with the ... Read More
AmitDiwan
814 Views
For exact match, set the values to be matched inside MongoDB $in(). Let us first create a collection with documents −> db.demo422.insertOne({"Name":"Chris", "Marks":34}); { "acknowledged" : true, "insertedId" : ObjectId("5e73a4059822da45b30346e1") } > db.demo422.insertOne({"Name":"Chris", "Marks":56}); { "acknowledged" : true, "insertedId" : ObjectId("5e73a40a9822da45b30346e2") } > db.demo422.insertOne({"Name":"David", "Marks":78}); { ... Read More
AmitDiwan
1K+ Views
To insert date in MongoDB, use Date(). Let us create a collection with documents −> db.demo421.insert({"DueDate":new Date(Date.now())}); WriteResult({ "nInserted" : 1 }) > db.demo421.insert({"DueDate":new Date("2020-01-15")}); WriteResult({ "nInserted" : 1 }) > db.demo421.insert({"DueDate":new Date("2018-12-31")}); WriteResult({ "nInserted" : 1 })Display all documents from a collection with the help of find() method −> ... Read More
AmitDiwan
523 Views
To combine unique items from array, use aggregate() in MongoDB. Let us create a collection with documents −> db.demo420.insert( ... { ... ... "details" : [ ... { ... "Value1":10, ... ... Read More
AmitDiwan
809 Views
Let us first create a collection with documents −>db.demo419.insertOne({"ProductInformation":[{"ProductName":"Product-1", "ProductPrice":500}, {"ProductName":"Product-2", "ProductPrice":600}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e724762b912067e57771ae8") }Display all documents from a collection with the help of find() method −> db.demo419.find();This will produce the following output −{ "_id" : ObjectId("5e724762b912067e57771ae8"), "ProductInformation" : [ { "ProductName" : ... Read More
AmitDiwan
806 Views
For this, use aggregate(). Let us first create a collection with documents −> db.demo418.insertOne( ... { ... "details":[ ... { ... "CountryName":"US", ... "Marks":45 ... }, ... Read More
AmitDiwan
1K+ Views
Let us first create a collection with documents −> db.demo417.insertOne({"EmployeeName":"Chris", "EmployeeSalary":500}); { "acknowledged" : true, "insertedId" : ObjectId("5e723ebbb912067e57771ae4") } > db.demo417.insertOne({"EmployeeName":"Mike", "EmployeeSalary":1000}); { "acknowledged" : true, "insertedId" : ObjectId("5e723ed7b912067e57771ae5") }Display all documents from a collection with the help of find() method −> db.demo417.find();This will produce the ... Read More
AmitDiwan
261 Views
To convert collection to capped, use runCommand(). It provides a helper to run specified database commands. Let us first create a collection with documents −> db.demo416.insertOne({"StudentName":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e723a7bb912067e57771adf") } > db.demo416.insertOne({"StudentName":"Mike"}); { "acknowledged" : true, "insertedId" : ObjectId("5e723a81b912067e57771ae0") } > db.demo416.insertOne({"StudentName":"Sam"}); ... Read More