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
122 Views
Let us create a collection with documents −> db.demo78.insertOne({"Name1":"Chris", "Name2":"Mike"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2bd99c71bf0181ecc4228f") } > db.demo78.insertOne({"Name1":"Bob", "Name2":"Carol"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2bd9ac71bf0181ecc42290") } > db.demo78.insertOne({"Name1":"David", "Name2":"Sam"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2bd9b671bf0181ecc42291") } > db.demo78.insertOne({"Name1":"Jace", "Name2":"John"}); { ... Read More
AmitDiwan
371 Views
To update MongoDB object, use UPDATE(). Let us create a collection with documents −> db.demo77.insertOne({"Details" : { "Score" : 78 } }); { "acknowledged" : true, "insertedId" : ObjectId("5e2bd6f371bf0181ecc4228a") }Display all documents from a collection with the help of find() method −> db.demo77.find();This will produce the following output ... Read More
AmitDiwan
454 Views
To implement multilevel $group, use MongoDB aggregate. Let us create a collection with documents −> db.demo76.insertOne({ Name:"Chris", "Age" : 21, "CountryName" : 'US' }); { "acknowledged" : true, "insertedId" : ObjectId("5e2bd3e571bf0181ecc42281") } > db.demo76.insertOne({ Name:"Chris", "Age" : 21, "CountryName" : 'US' }); { "acknowledged" : true, ... Read More
AmitDiwan
250 Views
To return only a specific number of elements, use aggregate() and $slice. Let us create a collection with documents −> db.demo75.insertOne({"Name":["Sam", "Mike", "Carol", "David", "Bob", "John"]}); { "acknowledged" : true, "insertedId" : ObjectId("5e2bcd7671bf0181ecc42278") }Display all documents from a collection with the help of find() method −> db.demo75.find();This will ... Read More
AmitDiwan
570 Views
Let us create a collection with documents −> db.demo74.insertOne( ... { ... StudentName: "Chris", ... StudentDetails: [{ ... "Subject": "MongoDB", ... "isRegular": "Active" ... }, { ... "Subject": "MongoDB", ... "isRegular": "InActive" ... }, { ... "Subject": ... Read More
AmitDiwan
1K+ Views
To get the first and last document in MongoDB, use aggregate() along with $first and $last respectively. Let us create a collection with documents −> db.demo73.insertOne({"Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e29c41b71bf0181ecc4226c") } . > db.demo73.insertOne({"Name":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5e29c41e71bf0181ecc4226d") } > ... Read More
AmitDiwan
697 Views
For this, use $let along with $expr. Here, $let is used to define temporary variable. The $expr is used for aggregation expressions. Let us create a collection with documents −> db.demo72.insertOne( ... { ... StudentDetails:[ ... { ... Name: "Chris", ... ... Read More
AmitDiwan
1K+ Views
To calculate sum of string in MongoDB, use aggregate(). Let us create a collection with documents −> db.demo71.insertOne({"Price":"20"}); { "acknowledged" : true, "insertedId" : ObjectId("5e29af210912fae76b13d76e") } > db.demo71.insertOne({"Price":"50"}); { "acknowledged" : true, "insertedId" : ObjectId("5e29af240912fae76b13d76f") } > db.demo71.insertOne({"Price":"20"}); { "acknowledged" : true, "insertedId" : ... Read More
AmitDiwan
144 Views
Concatenate deep sub-lists using aggregate() along with $unwind. Let us create a collection with documents −> db.demo70.insertOne( ... { ... ... "first" : [ ... { ... "details" : { ... ... Read More
AmitDiwan
301 Views
For this, use $where and compare with ==. Let us create a collection with documents −> db.demo69.insertOne( ... { ... "_id" : ObjectId("507c7f79bcf86cd7994f6c0e"), ... "Details" : { ... ... "id" : ObjectId("507c7f79bcf86cd7994f6c0e") ... } ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("507c7f79bcf86cd7994f6c0e") ... Read More