- 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 1659 Articles for Big Data Analytics
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
598 Views
To get max values for distinct elements, use $sort and $group in MongoDB aggregate(). Let us create a collection with documents −> db.demo750.insertOne({id:101, value:50}); { "acknowledged" : true, "insertedId" : ObjectId("5eae74b2a930c785c834e566") } > db.demo750.insertOne({id:102, value:40}); { "acknowledged" : true, "insertedId" : ObjectId("5eae74c8a930c785c834e567") } > db.demo750.insertOne({id:101, value:110}); { "acknowledged" : true, "insertedId" : ObjectId("5eae74dba930c785c834e568") }Display all documents from a collection with the help of find() method −> db.demo750.find();This will produce the following output −{ "_id" : ObjectId("5eae74b2a930c785c834e566"), "id" : 101, "value" : 50 } { "_id" : ObjectId("5eae74c8a930c785c834e567"), "id" : 102, "value" : 40 } ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
168 Views
To update each field of documents in collection with a formula, use MongoDB update(). Let us create a collection with documents −> db.demo749.insertOne({"details":[{"id":1, a:10}, {"id":2, a:5}, {"id":3, a:20}]}); { "acknowledged" : true, "insertedId" : ObjectId("5eae6fb0a930c785c834e565") }Display all documents from a collection with the help of find() method −> db.demo749.find().pretty();This will produce the following output −{ "_id" : ObjectId("5eae6fb0a930c785c834e565"), "details" : [ { "id" : 1, "a" : 10 }, { "id" : 2, ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
357 Views
The document is a record in a collection. Each document has the limitation of 16 MB size. The document is wrapped inside the curly bracket ({}).Let us create a collection with documents −> db.demo748.insertOne({_id:101, Name:"Chris", Age:21}); { "acknowledged" : true, "insertedId" : 101 } > db.demo748.insertOne({_id:102, Name:"Bob", Age:20}); { "acknowledged" : true, "insertedId" : 102 } > db.demo748.insertOne({_id:103, Name:"David", Age:23}); { "acknowledged" : true, "insertedId" : 103 } > db.demo748.insertOne({_id:104, Name:"Sam", Age:19}); { "acknowledged" : true, "insertedId" : 104 }Display all documents from a collection with the help of find() method −> db.demo748.find();This will produce the following output −{ "_id" ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
87 Views
To push values, use $push along with update() with multi field set to TRUE. Let us create a collection with documents −> db.demo747.insertOne({"CountryName":["US", "IND"]}); { "acknowledged" : true, "insertedId" : ObjectId("5eae6a50a930c785c834e55f") } > db.demo747.insertOne({"CountryName":["UK", "US"]}); { "acknowledged" : true, "insertedId" : ObjectId("5eae6a57a930c785c834e560") } > db.demo747.insertOne({"CountryName":["UK", "IND"]}); { "acknowledged" : true, "insertedId" : ObjectId("5eae6a60a930c785c834e561") }Display all documents from a collection with the help of find() method −> db.demo747.find();This will produce the following output −{ "_id" : ObjectId("5eae6a50a930c785c834e55f"), "CountryName" : [ "US", "IND" ] } { "_id" : ObjectId("5eae6a57a930c785c834e560"), "CountryName" : [ "UK", "US" ] } ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
To find posts older than current date in MongoDB, use $lte. Let us create a collection with documents −> db.demo746.insertOne({DueDate:new Date("2020-01-10")}); { "acknowledged" : true, "insertedId" : ObjectId("5eae67eca930c785c834e55b") } > db.demo746.insertOne({DueDate:new Date("2020-10-10")}); { "acknowledged" : true, "insertedId" : ObjectId("5eae67eda930c785c834e55c") } > db.demo746.insertOne({DueDate:new Date("2020-03-05")}); { "acknowledged" : true, "insertedId" : ObjectId("5eae67eea930c785c834e55d") } > db.demo746.insertOne({DueDate:new Date("2020-05-04")}); { "acknowledged" : true, "insertedId" : ObjectId("5eae67f1a930c785c834e55e") }Display all documents from a collection with the help of find() method −> db.demo746.find();This will produce the following output −{ "_id" : ObjectId("5eae67eca930c785c834e55b"), "DueDate" : ISODate("2020-01-10T00:00:00Z") } { "_id" : ObjectId("5eae67eda930c785c834e55c"), ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
304 Views
To concatenate with condition in MongoDB, use $cond and in that, work with $concat. Let us create a collection with documents −> db.demo745.insertOne({Value1:"100", Value2:"100"}); { "acknowledged" : true, "insertedId" : ObjectId("5eae6419a930c785c834e554") } > db.demo745.insertOne({Value1:"40", Value2:"50"}); { "acknowledged" : true, "insertedId" : ObjectId("5eae6421a930c785c834e555") } > db.demo745.insertOne({Value1:"13", Value2:"45"}); { "acknowledged" : true, "insertedId" : ObjectId("5eae6429a930c785c834e556") }Display all documents from a collection with the help of find() method −> db.demo745.find();This will produce the following output −{ "_id" : ObjectId("5eae6419a930c785c834e554"), "Value1" : "100", "Value2" : "100" } { "_id" : ObjectId("5eae6421a930c785c834e555"), "Value1" : "40", "Value2" : "50" } ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
140 Views
To find a certain element, use $project in MongoDB. Let us create a collection with documents −> db.demo744.insertOne( ... { ... studentInformation: ... [ ... { ... studentName:"Robert", ... grade:"A" ... }, ... { ... studentName:"Bob", ... grade:"C" ... }, ... { ... ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
74 Views
For this, use $$ROOT in MongoDB. Let us create a collection with documents −> db.demo743.insertOne({id:1, "ShippingDate":"2020-01-21", value:50}); { "acknowledged" : true, "insertedId" : ObjectId("5ead893a57bb72a10bcf0680") } > db.demo743.insertOne({id:2, "ShippingDate":"2020-05-10", value:30}); { "acknowledged" : true, "insertedId" : ObjectId("5ead893c57bb72a10bcf0681") } > db.demo743.insertOne({id:3, "ShippingDate":"2020-05-10", value:60}); { "acknowledged" : true, "insertedId" : ObjectId("5ead894657bb72a10bcf0682") } > db.demo743.insertOne({id:1, "ShippingDate":"2020-05-11", value:75}); { "acknowledged" : true, "insertedId" : ObjectId("5ead895657bb72a10bcf0683") }Display all documents from a collection with the help of find() method −> db.demo743.find();This will produce the following output −{ "_id" : ObjectId("5ead893a57bb72a10bcf0680"), "id" : 1, "ShippingDate" : "2020-01-21", "value" : 50 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
To fetch a specific element, iterate with forEach(). Let us create a collection with documents −> db.demo742.insertOne({ "userDetails": [ { "userName":"Robert", "CountryName":"UK" }, { "userName":"David", "CountryName":"AUS" } ]} ); { "acknowledged" : true, "insertedId" : ObjectId("5ead790b57bb72a10bcf0677") }Display all documents from a collection with the help of find() method −> db.demo742.find().pretty();This will produce the following output −{ "_id" : ObjectId("5ead790b57bb72a10bcf0677"), "userDetails" : [ { "userName" : "Robert", "CountryName" : "UK" }, { "userName" : "David", ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
100 Views
To update for _id, use $set in MongoDB. Let us create a collection with documents −db.demo741.insertOne({SubjectName:"MySQL"}); { "acknowledged" : true, "insertedId" : ObjectId("5ead718657bb72a10bcf0672") } > db.demo741.insertOne({SubjectName:"C"}); { "acknowledged" : true, "insertedId" : ObjectId("5ead718957bb72a10bcf0673") } > db.demo741.insertOne({SubjectName:"Java"}); { "acknowledged" : true, "insertedId" : ObjectId("5ead718e57bb72a10bcf0674") }Display all documents from a collection with the help of find() method −> db.demo741.find();This will produce the following output −{ "_id" : ObjectId("5ead718657bb72a10bcf0672"), "SubjectName" : "MySQL" } { "_id" : ObjectId("5ead718957bb72a10bcf0673"), "SubjectName" : "C" } { "_id" : ObjectId("5ead718e57bb72a10bcf0674"), "SubjectName" : "Java" }Following is the query to updating MongoDB for _id ... Read More