- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1359 Articles for MongoDB
272 Views
For this, use aggregate() in MongoDB. Let us create a collection with documents −> db.demo718.insertOne( ... { ... "id":101, ... "details": ... { ... "OtherDetails": ["Chris", "Mike", "Sam"], "GroupName": ["Group-1"], "Info": [] ... } ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5eaae25843417811278f5880") } > db.demo718.insertOne( ... { ... "id":102, ... "details": ... { ... "OtherDetails": ["Chris", "David"], "GroupName": ["Group-1"], "Info": [] ... ... Read More
204 Views
For aggregation, use aggregate() in MongoDB. Group the dates with $group. Let us create a collection with documents −> db.demo717.insertOne( ... { ... "shippingdetails": ... [ ... { ... duedate:"2020-04-29 22:33:04", ... }, ... { ... duedate:"2020-03-29 22:33:04", ... }, ... { ... duedate:"2020-04-29 22:33:04", ... }, ... ... Read More
439 Views
To remove an object in a child collection, use $pull in MongoDB. Let us create a collection with documents −> db.demo715.insertOne({ ... _id:1, ... details : ... [ ... { 'id' : '101', ... 'Information' : [ ... { ... 'studentid' : '102', ... "Name":"Bob" ... }, ... { ... 'studentid' : '103', ... "Name":"Chris" ... Read More
75 Views
Let us create a collection with documents −> db.demo714.insertOne({FirstName:"Chris", LastName:"Brown"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea9a2da85324c2c98cc4c2b") } > db.demo714.insertOne({FirstName:"Adam", LastName:"Smith"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea9a2e585324c2c98cc4c2c") } > db.demo714.insertOne({FirstName:"David", LastName:"Miller"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea9a2ed85324c2c98cc4c2d") } > db.demo714.insertOne({FirstName:"John", LastName:"Doe"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea9a2f785324c2c98cc4c2e") }Display all documents from a collection with the help of find() method −> db.demo714.find();This will produce the following output −{ "_id" : ObjectId("5ea9a2da85324c2c98cc4c2b"), "FirstName" : "Chris", "LastName" : "Brown" } { "_id" : ObjectId("5ea9a2e585324c2c98cc4c2c"), "FirstName" : "Adam", "LastName" : "Smith" } { ... Read More
58 Views
Use $ along with update command to update tag records. Let us create a collection with documents −> db.demo713.insertOne( ... { ... tags: ... [ ... { ... id:101, ... Name:"Tag-1" ... }, ... { ... id:102, ... Name:"Tag-3" ... }, ... { ... ... Read More
388 Views
To add a new field, use $addFields in MongoDB. Let us create a collection with documents −> db.demo712.insertOne({"Name":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea85f675d33e20ed1097b82") } > db.demo712.insertOne({"Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea85f6a5d33e20ed1097b83") } > db.demo712.insertOne({"Name":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea85f6e5d33e20ed1097b84") }Display all documents from a collection with the help of find() method −> db.demo712.find();This will produce the following output −{ "_id" : ObjectId("5ea85f675d33e20ed1097b82"), "Name" : "John" } { "_id" : ObjectId("5ea85f6a5d33e20ed1097b83"), "Name" : "Chris" } { "_id" : ObjectId("5ea85f6e5d33e20ed1097b84"), "Name" : "Bob" }Following is the query to add a ... Read More
1K+ Views
Let us create a collection with documents −> db.demo711.insertOne({Name:"John", "Marks":75, Age:21, status:"Active"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea85c215d33e20ed1097b7e") } > db.demo711.insertOne({Name:"Chris", "Marks":55, Age:22, status:"Active"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea85c2c5d33e20ed1097b7f") } > db.demo711.insertOne({Name:"Bob", "Marks":45, Age:20, status:"Inactive"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea85c3e5d33e20ed1097b80") } > db.demo711.insertOne({Name:"David", "Marks":85, Age:23, status:"Active"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea85c775d33e20ed1097b81") }Display all documents from a collection with the help of find() method −> db.demo711.find();This will produce the following output −{ "_id" : ObjectId("5ea85c215d33e20ed1097b7e"), "Name" : "John", "Marks" : 75, "Age" : 21, "status" : ... Read More
858 Views
The $natural returns the documents in natural order. To reverse the items, use $natural:-1. Let us create a collection with documents −> db.demo710.insertOne({id:101, Name:"Robert"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea83a855d33e20ed1097b7a") } > db.demo710.insertOne({id:102, Name:"Carol"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea83a8d5d33e20ed1097b7b") } > db.demo710.insertOne({id:103, Name:"Mike"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea83a935d33e20ed1097b7c") } > db.demo710.insertOne({id:104, Name:"Sam"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea83a9b5d33e20ed1097b7d") }Display all documents from a collection with the help of find() method −> db.demo710.find();This will produce the following output −{ "_id" : ObjectId("5ea83a855d33e20ed1097b7a"), "id" : 101, "Name" : ... Read More
94 Views
To get the sorted list of marks, use $sort. Use $limit: 2 to display only two such documents with least marks. Let us create a collection with documents −> db.demo709.insertOne({Name:"John", "Marks":75}); { "acknowledged" : true, "insertedId" : ObjectId("5ea839005d33e20ed1097b76") } > db.demo709.insertOne({Name:"Chris", "Marks":45}); { "acknowledged" : true, "insertedId" : ObjectId("5ea839075d33e20ed1097b77") } > db.demo709.insertOne({Name:"David", "Marks":54}); { "acknowledged" : true, "insertedId" : ObjectId("5ea839125d33e20ed1097b78") } > db.demo709.insertOne({Name:"Bob", "Marks":69}); { "acknowledged" : true, "insertedId" : ObjectId("5ea839295d33e20ed1097b79") }Display all documents from a collection with the help of find() method −> db.demo709.find();This will produce the following output −{ "_id" ... Read More
To Continue Learning Please Login
Login with Google