- Trending Categories
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 1349 Articles for MongoDB
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
563 Views
The $group in MongoDB is used to group input documents by the specified _id expression. Let us create a collection with documents −> db.demo466.insertOne( ... { ... ... "ProductPrice" :150, ... "ProductQuantity" : 1, ... "ProductName" : "Product-1", ... "ActualAmount" :110, ... "ProductProfit" : 40, ... "ProductId" : 1 ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e80477cb0f3fa88e2279066") } > > db.demo466.insertOne( ... { ... ... "ProductPrice" :150, ... "ProductQuantity" : 1, ... "ProductName" : "Product-1", ... "ActualAmount" :110, ... "ProductProfit" : 40, ... "ProductId" : 2 ... } ... ); { "acknowledged" : true, ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
54 Views
For this, simply use dot notation with find() in MongoDB. Let us create a collection with documents −> db.demo465.insertOne( ... { ... id: 101, ... details: [{ ... Name: "Chris", ... Info: { ... Subject: "MongoDB", ... Marks:67 ... } ... }, { ... Name: "David", ... Info: { ... Subject: "MySQL", ... Marks:78 ... } ... ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
278 Views
To exclude array type field value, use delete() in MongoDB. Let us create a collection with documents −> db.demo464.insertOne( ... { ... ... "id" : "101", ... "details": [ ... { ... Name:"Chris" ... }, ... { ... Name:"David" ... } ... ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e7f8832cb66ccba22cc9dda") }Display all documents from a collection with the help of find() method −> db.demo464.find();This will produce the following output −{ "_id" ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
539 Views
To return a single document from a collection, use findOne() in MongoDB. Let us create a collection with documents −> db.demo463.insertOne({"StudentName":"Chris Brown", "StudentAge":21, "StudentCountryName":"US"});{ "acknowledged" : true, "insertedId" : ObjectId("5e7f7ec8cb66ccba22cc9dcf") } > db.demo463.insertOne({"StudentName":"David Miller", "StudentAge":23, "StudentCountryName":"UK"});{ "acknowledged" : true, "insertedId" : ObjectId("5e7f7ed5cb66ccba22cc9dd0") } > db.demo463.insertOne({"StudentName":"John Doe", "StudentAge":22, "StudentCountryName":"AUS"});{ "acknowledged" : true, "insertedId" : ObjectId("5e7f7ee1cb66ccba22cc9dd1") } > db.demo463.insertOne({"StudentName":"John Smith", "StudentAge":24, "StudentCountryName":"US"});{ "acknowledged" : true, "insertedId" : ObjectId("5e7f7eefcb66ccba22cc9dd2") }Display all documents from a collection with the help of find() method −> db.demo463.find();This will produce the following output −{ "_id" : ObjectId("5e7f7ec8cb66ccba22cc9dcf"), "StudentName" : "Chris ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
190 Views
To update a specific document in array with $set and positional $ operator, use MongoDB updateOne(). The updateOne() updates a single document in a collection based on a query filter.Let us create a collection with documents −> db.demo462.insertOne( ... { ... "id":1, ... "DueDateDetails": [ ... { ... "Name": "David", ... "Age":21, ... "CountryName":["US", "UK"] ... }, ... { ... ... "Name": "Chris", ... "Age":23, ... ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
196 Views
To update tag in MongoDB, use the update command. Let us create a collection with documents −> db.demo713.insertOne( ... { ... tags: ... [ ... { ... id:101, ... Name:"Tag-1" ... }, ... { ... id:102, ... Name:"Tag-3" ... }, ... { ... id:103, ... Name:"Tag-3" ... } ... ] ... } ... ); { ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
564 Views
To cast to ObjectId correctly, use aggregate() in MongoDB. Let us create a collection with documents −> db.demo460.insertOne({"_id":"5ab9cbfa31c2ab715d42129e"}); { "acknowledged" : true, "insertedId" : "5ab9cbfa31c2ab715d42129e" }Display all documents from a collection with the help of find() method −> db.demo460.find();This will produce the following output −{ "_id" : "5ab9cbfa31c2ab715d42129e" }Following is the query to cast to objectId −> db.demo460.aggregate( [ idConvert ]) This will produce the following output −{ "_id" : "5ab9cbfa31c2ab715d42129e", "value" : ObjectId("5ab9cbfa31c2ab715d42129e") }
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
810 Views
To get items from an object array, use aggregate(). Let us create a collection with documents −> db.demo459.insertOne( ... { "_id" : 1, ... "Information" : [ ... { ... "Name" : "Chris", ... "_id" : new ObjectId(), ... "details" : [ ... "HR" ... ] ... }, ... { ... ... "Name" : "David", ... "_id" : new ObjectId(), ... "details" : [ ... "Developer" ... ] ... }, ... { ... ... ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
321 Views
To update a record, you need to update on the basis of _id. Let us create a collection with documents −> db.demo458.insertOne( {_id:101, "Name":"David" } ); { "acknowledged" : true, "insertedId" : 101 } > db.demo458.insertOne( {_id:102, "Name":"Chris" } ); { "acknowledged" : true, "insertedId" : 102 } > db.demo458.insertOne( {_id:103, "Name":"Bob" } ); { "acknowledged" : true, "insertedId" : 103 }Display all documents from a collection with the help of find() method −> db.demo458.find();This will produce the following output −{ "_id" : 101, "Name" : "David" } { "_id" : 102, "Name" : "Chris" } { "_id" : 103, ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
105 Views
For this, use $project in MongoDB. Within that, use $filter. Let us create a collection with documents −> db.demo457.insertOne( ... { ... _id: 101, ... details: [ ... { ProductName:"Product-1" , ProductPrice:90 }, ... { ProductName:"Product-2" , ProductPrice:190 } ... ] ... } ... ); { "acknowledged" : true, "insertedId" : 101 } > > db.demo457.insertOne( ... { ... _id: 102, ... details: [ ... { ProductName:"Product-3" , ProductPrice:150}, ... { ProductName:"Product-4" , ProductPrice:360 } ... ] ... } ... ); { ... Read More