- 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)
2K+ Views
For this, use $lookup. This performs a left outer join to an unsharded collection in the same database to filter in documents from the “joined” collection for processing.Let us first create a collection with documents −> db.demo395.insertOne({Name:"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e5e782317aa3ef9ab8ab207") } > db.demo395.insertOne({Name:"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e5e782317aa3ef9ab8ab208") }Display all documents from a collection with the help of find() method −> db.demo395.find();This will produce the following output −{ "_id" : ObjectId("5e5e782317aa3ef9ab8ab207"), "Name" : "Chris" } { "_id" : ObjectId("5e5e782317aa3ef9ab8ab208"), "Name" : "David" }Let us create a second collection with documents ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
160 Views
Let us first create a collection with documents −> db.demo394.insertOne( ... { ... ... details: [ ... { ... _id: '1', ... startDate: '2018-01-11T07:00:00.000Z', ... endDate: '2019-01-12T07:59:59.999Z' ... }, ... { ... _id: '2', ... startDate: '2019-01-21T07:00:00.000Z', ... endDate: '2020-01-04T07:59:59.999Z' ... } ... ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e5e716817aa3ef9ab8ab202") }Display all ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
296 Views
For this, use aggregate(). Let us first create a collection with documents −> db.demo393.insertOne( ... { ... Id1: "1", ... Name: "Chris", ... Id2: "100" ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e5e6dd522064be7ab44e804") } > db.demo393.insertOne( ... { ... Id1: "1", ... Name: "Chris", ... Id2: "101" ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e5e6dd522064be7ab44e805") } > db.demo393.insertOne( ... { ... Id1: "3", ... ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
451 Views
To pull values, use $pull and set multi: true. Let us first create a collection with documents −> db.demo392.insertOne( ... { ... Name: 'Chris', ... details: [ ... { ... _id: '101' ... ... }, ... { ... _id: '102' ... } ... ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e5d2b3322064be7ab44e802") } > > db.demo392.insertOne( ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
475 Views
To get a single element, use aggregation and LIMIT. The skip() is used to skip a specific number of documents.Let us first create a collection with documents −> db.demo391.insertOne( ... { "_id" : 101, "Name" : "Chris", Values: ["101", "102"] } ... ) { "acknowledged" : true, "insertedId" : 101 } > db.demo391.insertOne( ... { "_id" : 111, "Name" : "Chris", Values: ["101", "102"] } ... ) { "acknowledged" : true, "insertedId" : 111 } > db.demo391.insertOne( ... { "_id" : 121, "Name" : "Chris", Values: ["101", "102"] } ... ) { "acknowledged" : true, "insertedId" : ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
365 Views
You need to set multi to true. Include the option multi − true to update all documents that match the query criteria.Let us first create a collection with documents −> db.demo390.insertOne({"FirstName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e5d1f3a22064be7ab44e7fa") } > db.demo390.insertOne({"FirstName":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e5d1f3e22064be7ab44e7fb") } > db.demo390.insertOne({"FirstName":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5e5d1f4122064be7ab44e7fc") } > db.demo390.insertOne({"FirstName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e5d1f4422064be7ab44e7fd") }Display all documents from a collection with the help of find() method −> db.demo390.find();This will produce the following output −{ "_id" : ObjectId("5e5d1f3a22064be7ab44e7fa"), "FirstName" ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
300 Views
To remove, use $pull in MongoDB. Let us first create a collection with documents −> db.demo388.insertOne( ... { ... _id: '101', ... userDetails: { ... isMarried: false, ... userInfo: [ ... { ... Name:"Chris", ... Age:21 ... ... } ... ] ... } ... } ... ); { "acknowledged" : true, ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
505 Views
To unwind, means to deconstruct an array field from the input documents to output a document for each element.To unwind arrays, use $unwind in MongoDB aggregation. Let us first create a collection with documents −> db.demo387.insertOne( ... { ... ... "Name" : "101", ... "Details1" : [ ... {Value:100, Value1:50, Value2:40}, ... {Value:200}, ... {Value:300} ... ], ... "Details" : [ ... {Value:100, Value1:30, Value2:26}, ... {Value:200}, ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
247 Views
Let us first create a collection with documents −> db.demo386.insert( ... { ... details: { Month: 02, Day: 27, Year: 2020 } ... } ... ); WriteResult({ "nInserted" : 1 })Display all documents from a collection with the help of find() method −> db.demo386.find();This will produce the following output −{ "_id" : ObjectId("5e5bd9a222064be7ab44e7f7"), "details" : { "Month" : 2, "Day" : 27, "Year" : 2020 } }Following is the query to convert date parts to date −> db.demo386.aggregate( ... {"$project":{ ... "_id":0, ... "DueDate":{ ... "$dateToString":{ ... "format":"%m-%d-%Y", ... "date":{"$dateFromParts": {"year":"$details.Year","month":"$details.Month","day":"$details.Day"}} ... } ... } ... }} ... );This will produce the following output −{ "DueDate" : "02-27-2020" }