- 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)
431 Views
To find the oldest date, use $min in MongoDB aggregate(). Let us create a collection with documents −> db.demo353.insertOne({"Date1":new ISODate("2019-01-10"), "Date2":new ISODate("2016-01-21"), "Date3":new ISODate("2020-04-11")}); { "acknowledged" : true, "insertedId" : ObjectId("5e568261f8647eb59e5620be") } > db.demo353.insertOne({"Date1":new ISODate("2011-11-20"), "Date2":new ISODate("2013-12-10"), "Date3":new ISODate("2014-01-05")}); { "acknowledged" : true, "insertedId" : ObjectId("5e56827ff8647eb59e5620bf") }Display all documents from a collection with the help of find() method −> db.demo353.find();This will produce the following output −{ "_id" : ObjectId("5e568261f8647eb59e5620be"), "Date1" : ISODate("2019-01-10T00:00:00Z"), "Date2" : ISODate("2016-01-21T00:00:00Z"), "Date3" : ISODate("2020-04-11T00:00:00Z") } { "_id" : ObjectId("5e56827ff8647eb59e5620bf"), "Date1" : ISODate("2011-11-20T00:00:00Z"), "Date2" : ISODate("2013-12-10T00:00:00Z"), "Date3" : ISODate("2014-01-05T00:00:00Z") }Following is the query ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
408 Views
To update selected fields, use UPDATE() in MongoDB. The $set is used to set the new value. Let us create a collection with documents −> db.demo352.insertOne({"Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e55510af8647eb59e5620ba") } > db.demo352.insertOne({"Name":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e55510ef8647eb59e5620bb") } > db.demo352.insertOne({"Name":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5e555112f8647eb59e5620bc") } > db.demo352.insertOne({"Name":"Mike"}); { "acknowledged" : true, "insertedId" : ObjectId("5e555115f8647eb59e5620bd") }Display all documents from a collection with the help of find() method −> db.demo352.find();This will produce the following output −{ "_id" : ObjectId("5e55510af8647eb59e5620ba"), "Name" : "Chris" } { "_id" ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
149 Views
For this, use aggregate() in MongoDB. Let us create a collection with documents −> db.demo351.insertOne( ... { ... ... "_id" : "101", ... "ProductDetails" : [ ... { ... "ProductName" : "Product-1", ... "ProductPrice" :500 ... }, ... { ... "ProductName" : "Product-2", ... "ProductPrice" :400 ... } ... ] ... } ... ); { "acknowledged" : true, "insertedId" : "101" } > db.demo351.insertOne( ... { ... ... ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
To query deeply nested objects, use dot(.) notation in MongoDB. Let us create a collection with documents −> db.demo350.insertOne( ... { ... id:101, ... Name: "Chris", ... details: [ ... { ... _id: 1, ... ClientNumber: "10001", ... ClientDetails: [ . ... { ... Name:"David", ... Age:29 ... }, ... ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
244 Views
The findOneAndUpdate() is used to update only a single document in MongoDB. Let us create a collection with documents −db.demo349.insertOne({"Name":"Chris", "Marks":56}); { "acknowledged" : true, "insertedId" : ObjectId("5e55384af8647eb59e5620b4") } > db.demo349.insertOne({"Name":"David", "Marks":78}); { "acknowledged" : true, "insertedId" : ObjectId("5e553853f8647eb59e5620b5") } > db.demo349.insertOne({"Name":"Chris", "Marks":89}); { "acknowledged" : true, "insertedId" : ObjectId("5e55385af8647eb59e5620b6") } > db.demo349.insertOne({"Name":"David", "Marks":54}); { "acknowledged" : true, "insertedId" : ObjectId("5e55385ff8647eb59e5620b7") }Display all documents from a collection with the help of find() method −> db.demo349.find();This will produce the following output −{ "_id" : ObjectId("5e55384af8647eb59e5620b4"), "Name" : "Chris", "Marks" : 56 } { ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
231 Views
To unset objects in MongoDB, use $unset. Let us create a collection with documents −> db.demo348.insertOne( ... { ... "details": { ... "studentDetails": ... { ... StudentName: "Robert" ... } ... } ... ... }); { "acknowledged" : true, "insertedId" : ObjectId("5e553556f8647eb59e5620b2") } > db.demo348.insertOne( ... { ... "details": { ... "studentDetails": ... { ... StudentName: "Mike" ... } ... ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
338 Views
To check duplicates in the inner array, use aggregate() in MongoDB. Let us create a collection with documents −> db.demo347.insertOne( ... { ... "details": { ... "details1": [ ... { ... Name: "Chris", ... Age: 21 ... } ... ... ] ... } ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e5532eaf8647eb59e5620af") } > ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
146 Views
To query an array of embedded documents based on range, use aggregate(). Let us create a collection with documents −> db.demo346.insertOne( ... { ... _id: 101, ... userDetails: [ ... { UserName: "Chris", Score:78}, ... { UserName: "David", Score:68}, ... { UserName: "Bob", Score:88} ... ] ... } ... ); { "acknowledged" : true, "insertedId" : 101 } > db.demo346.insertOne( ... { ... _id: 102, ... userDetails: [ ... ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
474 Views
Let us create a collection with documents −> db.demo345.insertOne({ ... "UserName" : "Robert", ... "UserDetails" : [ ... { ... "isMarried" : false, ... "CountryName":"US" ... ... }, ... { ... "isMarried" : true, ... "CountryName":"UK" ... ... }, ... { ... "isMarried" : false, ... ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
110 Views
Let us create a collection with documents −> db.demo344.insertOne({"startDate":"2020-02-24 10:50:00", "endDate":"2020-02-24 11:50:00"}); { "acknowledged" : true, "insertedId" : ObjectId("5e53f52cf8647eb59e5620aa") } > db.demo344.insertOne({"startDate":"2020-02-24 08:00:00", "endDate":"2020-02-24 11:50:50"}); { "acknowledged" : true, "insertedId" : ObjectId("5e53f53df8647eb59e5620ab") }Display all documents from a collection with the help of find() method −> db.demo344.find();This will produce the following output −{ "_id" : ObjectId("5e53f52cf8647eb59e5620aa"), "startDate" : "2020-02-24 10:50:00", "endDate" : "2020-02-24 11:50:00" } { "_id" : ObjectId("5e53f53df8647eb59e5620ab"), "startDate" : "2020-02-24 08:00:00", "endDate" : "2020-02-24 11:50:50" }Following is how to query objects with the longest time period −> db.demo344.aggregate([ ... { $addFields: { ... ... Read More