- 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
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
511 Views
Use $mod to get the even numbers and pull them from the array. Let us first create a collection with documents −>db.pullEvenNumbersDemo.insertOne({"AllNumbers":[101, 102, 104, 106, 108, 109, 110, 112, 14, 17, 18, 21]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd45b072cba06f46efe9eea") }Following is the query to display all documents from the collection with the help of find() method −> db.pullEvenNumbersDemo.find().pretty();This will produce the following output −{ "AllNumbers" : [ 102, 104, 106, 108, 109, 110, 112, ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
419 Views
You can use update() along with $ operator for this. Let us first create a collection with documents −> db.addAFieldDemo.insertOne( ... { ... ... "ClientName" : "Larry", ... "ClientCountryName" : "US", ... "ClientOtherDetails" : [ ... { ... "ClientProjectName":"Online Banking System" ... } ... ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5cd44bdc2cba06f46efe9ee8") }Following is the query to display all documents from a collection with the help of find() method −> db.addAFieldDemo.find().pretty();This ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
281 Views
You can use $avg operator along with aggregate framework. Let us first create a collection with documents −> db.averageOfRatingsInArrayDemo.insertOne( ... { ... "StudentDetails":[ ... { ... "StudentId":1, ... "StudentScore":45 ... }, ... { ... "StudentId":2, ... "StudentScore":58 ... }, ... { ... "StudentId":3, ... ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
221 Views
You can use $or operator along with limit(1) to match element in array. Let us first create a collection with documents −> db.matchElementInArrayDemo.insertOne( ... { ... "StudentName" : "Chris" , ... "StudentOtherDetails" : ... [ ... {"StudentCountryName" : "US" , "StudentSkills" : "MongoDB"}, ... {"StudentCountryName" : "UK" , "StudentSkills" : "Java"} ... ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5cd423282cba06f46efe9ee2") } > db.matchElementInArrayDemo.insertOne( ... { ... "StudentName" : "Chris" , ... ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
363 Views
To get specific object from array of objects, use positional operator($). Let us first create a collection with documents −> db.getASpecificObjectDemo.insertOne( ... { ... _id :1, f ... "CustomerName" : "Larry", ... "CustomerDetails" : { ... "CustomerPurchaseDescription": [{ ... id :100, ... "ProductName" : "Product-1", ... "Amount":10000 ... }, { ... id :101, ... "ProductName" : ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
136 Views
You can use aggregate framework for this. Let us first create a collection with documents −> db.summingSubDocumentDemo.insertOne( ... { "_id" :101, "CustomerDetails" : { "CustomerPurchase" : { "CustomerPurchaseAmount" : 2000 } } }); { "acknowledged" : true, "insertedId" : 101 } > db.summingSubDocumentDemo.insertOne( { "_id" :102, "CustomerDetails" : { "CustomerPurchase" : { "CustomerPurchaseAmount" : 3000 } } }); { "acknowledged" : true, "insertedId" : 102 } > db.summingSubDocumentDemo.insertOne( { "_id" :103, "CustomerDetails" : { "CustomerPurchase" : { "CustomerPurchaseAmount" : 5000 } } }); { "acknowledged" : true, "insertedId" : 103 }Following is the query to display all documents ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
112 Views
To retrieve multiple items in an array, use aggregate framework. Let us first create a collection with documents −> db.retrieveMultipleDemo.insertOne( ... { ... "UserDetails": ... [ ... { "_id": "101", "UserName":"John", "UserAge": 23 }, ... { "_id": "102", "UserName":"Carol", "UserAge": 21 }, ... { "_id": "103", "UserName":"David", "UserAge": 23}, ... { "_id": "104", "UserName":"Sam", "UserAge": 25} ... ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5cd40c85edc6604c74817cf0") }Following is the query to ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
57 Views
You can use aggregate framework for this. Here, we will get the sum and then match it to search for documents less than a particular number. Let us first create a collection with documents −> db.searchDocumentsDemo.insertOne({"Value1":100, "Value2":560}); { "acknowledged" : true, "insertedId" : ObjectId("5cd3fe1eedc6604c74817ce9") } > db.searchDocumentsDemo.insertOne({"Value1":300, "Value2":150}); { "acknowledged" : true, "insertedId" : ObjectId("5cd3fe29edc6604c74817cea") } > db.searchDocumentsDemo.insertOne({"Value1":400, "Value2":200}); { "acknowledged" : true, "insertedId" : ObjectId("5cd3fe30edc6604c74817ceb") } > db.searchDocumentsDemo.insertOne({"Value1":190, "Value2":210}); { "acknowledged" : true, "insertedId" : ObjectId("5cd3fe45edc6604c74817cec") }Following is the query to display all documents from a collection with the help of ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
238 Views
Let us first create a collection with documents −>db.missingDocumentDemo.insertOne({"StudentFirstName":"Adam", "StudentLastName":"Smith"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd3fb1eedc6604c74817ce6") } >db.missingDocumentDemo.insertOne({"StudentFirstName":"Carol", "StudentLastName":"Taylor"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd3fb29edc6604c74817ce7") } >db.missingDocumentDemo.insertOne({"StudentFirstName":"David", "StudentLastName":"Miller", "StudentAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5cd3fb40edc6604c74817ce8") }Following is the query to display all documents from a collection with the help of find() method −> db.missingDocumentDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd3fb1eedc6604c74817ce6"), "StudentFirstName" : "Adam", "StudentLastName" : "Smith" } { "_id" : ObjectId("5cd3fb29edc6604c74817ce7"), "StudentFirstName" : "Carol", "StudentLastName" : "Taylor" } { "_id" : ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
75 Views
You can use $and operator for this. Let us first create a collection with documents −> db.twoSpecificIdsDemo.insertOne( ... { ... PlayerId:1, ... "PlayerDetails": [{ ... id: 100, ... "PlayerName":"Chris" ... }, { ... id: 101, ... "PlayerName":"Sam" ... }, { ... id: 102, ... "PlayerName":"Robert" ... }, { ... id: 103, ... "PlayerName":"Carol" ... }] ... Read More