- 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
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
237 Views
To retrieve an embedded object as a document, use the aggregation $replaceRoot. Let us first create a collection with documents −> db.embeddedObjectDemo.insertOne( { _id: new ObjectId(), "UserDetails": { "UserName": "John", "UserAge": 24, "UserEmailId": "John22@gmail.com" } } ); { "acknowledged" : true, "insertedId" : ObjectId("5ced580fef71edecf6a1f693") } > db.embeddedObjectDemo.insertOne( { _id: new ObjectId(), "UserDetails": { "UserName": "Carol", "UserAge": 26, "UserEmailId": "Carol123@gmail.com" } } ); { "acknowledged" : true, "insertedId" : ObjectId("5ced5828ef71edecf6a1f694") }Following is the query to display all documents from a collection with the help of find() method −> db.embeddedObjectDemo.find().pretty();This will produce the ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
126 Views
To query array of nested string, you can use the dot(.) notation. Let us first create a collection with documents −> db.nestedStringDemo.insertOne( { "CustomerName": "John", "CustomerOtherDetails": [ { "Age":29, "CountryName": "US" }, { "CompanyName": "Amazon", "Salary": 150000, "ProjectName": ["Online Library Management System", "Pig Dice Game"] } ] } ); { "acknowledged" : true, "insertedId" : ObjectId("5cea4629ef71edecf6a1f690") } > db.nestedStringDemo.insertOne( { "CustomerName": "Chris", "CustomerOtherDetails": [ { "Age":27, "CountryName": "AUS" }, { "CompanyName": "Google", "Salary": 250000, "ProjectName": ["Chat Application", "Game ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
226 Views
You can use positional operator $. Let us first create a collection with documents −> db.replaceAnArrayFieldValueDemo.insertOne({"StudentTechnicalSubjects":["MySQL", "SQL Server", "PL/SQL"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cea41e0ef71edecf6a1f68f") }Following is the query to display all documents from a collection with the help of find() method −> db.replaceAnArrayFieldValueDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cea41e0ef71edecf6a1f68f"), "StudentTechnicalSubjects" : [ "MySQL", "SQL Server", "PL/SQL" ] }Following is the query to replace an array field value. Here, we are updating “SQL Server” with “MongoDB” −> db.replaceAnArrayFieldValueDemo.update( {"StudentTechnicalSubjects":"SQL Server"}, ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
147 Views
Yes, for this, use $indexOfCP operator along with aggregate framework. Let us first create a collection with documents −> db.patterDemo.insertOne( { "ClientName": "John", "ClientWebsiteName":"webbuziness.com/John/business" } ); { "acknowledged" : true, "insertedId" : ObjectId("5cea40acef71edecf6a1f68d") } > db.patterDemo.insertOne( { "ClientName": "Carol", "ClientWebsiteName":"solvecoding.com/business" } ); { "acknowledged" : true, "insertedId" : ObjectId("5cea40acef71edecf6a1f68e") }Following is the query to display all documents from a collection with the help of find() method −> db.patterDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cea40acef71edecf6a1f68d"), "ClientName" : "John", "ClientWebsiteName" : "abcd.com" ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
209 Views
For this, use aggregate framework with the $elemMatch operator. Let us first create a collection with documents −> db.matchMultipleCriteriaDemo.insertOne({ "EmployeeDetails": [ {"EmployeeName": "Chris", "Salary": 45000, "Language":"Java"}, {"EmployeeName": "Robert", "Salary": 41000, "Language":"Python"} ] }); { "acknowledged" : true, "insertedId" : ObjectId("5cea3bf0ef71edecf6a1f689") } > db.matchMultipleCriteriaDemo.insertOne({ "EmployeeDetails": [ {"EmployeeName": "David", "Salary": 55000, "Language":"C++"}, {"EmployeeName": "Bob", "Salary": 61000, "Language":"C"} ] }); { "acknowledged" : true, "insertedId" : ObjectId("5cea3bf1ef71edecf6a1f68a") }Following is the query to display all documents from a collection with the help of find() ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
136 Views
For this, you can use $elemMatch operator. The $elemMatch operator matches documents that contain an array field with at least one element that matches all the specified query criteria. Let us first create a collection with documents −> db.filterBySeveralElementsDemo.insertOne( "_id":100, "StudentDetails": [ { "StudentName": "John", "StudentCountryName": "US", }, { "StudentName": "Carol", "StudentCountryName": "UK" } ] } ); { "acknowledged" : true, "insertedId" : 100 } > db.filterBySeveralElementsDemo.insertOne( { ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
321 Views
Use $avg operator along with aggregate framework. Let us first create a collection with documents. Here, one of the fields is StudentScore −> db.averageReturiningNullDemo.insertOne( {"StudentDetails" : { "StudentScore" : 89 } }); { "acknowledged" : true, "insertedId" : ObjectId("5ce9822e78f00858fb12e927") } > db.averageReturiningNullDemo.insertOne( {"StudentDetails" : { "StudentScore" : 34 } }); { "acknowledged" : true, "insertedId" : ObjectId("5ce9822e78f00858fb12e928") } > db.averageReturiningNullDemo.insertOne( {"StudentDetails" : { "StudentScore" : 78 } }); { "acknowledged" : true, "insertedId" : ObjectId("5ce9822e78f00858fb12e929") }Following is the query to display all documents from a collection with the help of find() ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
710 Views
MongoDB supports the BSON format data, so there is no max length of field name. Let us first create a collection with documents −>db.maxLengthDemo.insertOne({"maxLengthhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh":"This is demo"}); { "acknowledged" : true, "insertedId" : ObjectId("5ce97ac978f00858fb12e926") }Following is the query to display all documents from a collection with the help of find() method −> db.maxLengthDemo.find();This will produce the following output.{ "_id"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hhhhh hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" : "This is demo" }
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
135 Views
To update a single list item, use positional operator($). Let us first create a collection with documents −> db.updateASingleListDemo.insertOne({ _id:1, "EmployeeName":"Chris", "EmployeeDetails": [ {"EmployeeId":"EMP-101", "EmployeeSalary": 18999 }] }); { "acknowledged" : true, "insertedId" : 1 }Following is the query to display all documents from a collection with the help of find() method −> db.updateASingleListDemo.find().pretty();This will produce the following output −{ "_id" : 1, "EmployeeName" : "Chris", "EmployeeDetails" : [ { "EmployeeId" : "EMP-101", "EmployeeSalary" : 18999 } ] }Following is the query ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
87 Views
To retrieve array values, use dot(.) notation. Let us first create a collection with documents −> db.retrievingArrayDemo.insertOne( { "UserDetails" : [ { "UserName" : "John", "UserAge" : 23 } ], "UserCountryName" : "AUS", "UserLoginDate" : new ISODate(), "UserMessage" : "Hello" } ); { "acknowledged" : true, "insertedId" : ObjectId("5ce9718478f00858fb12e920") } > db.retrievingArrayDemo.insertOne( { "UserDetails" : [ { "UserName" : "Sam", "UserAge" : 24 } ], "UserCountryName" : "UK", "UserLoginDate" : new ISODate(), "UserMessage" : "Bye" } ); { "acknowledged" : true, "insertedId" : ObjectId("5ce9718478f00858fb12e921") }Following is the query to display all documents from a collection with the help of find() method −> db.retrievingArrayDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5ce9718478f00858fb12e920"), ... Read More