- 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)
362 Views
Use $set operator along with update() for this. Let us first create a collection with documents. Here we have set one field as NumberLong −> db.findAndReplaceDemo.insertOne({"UserId":NumberLong(101)}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2c960b64f4b851c3a13b6") } > db.findAndReplaceDemo.insertOne({"UserId":NumberLong(110)}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2c966b64f4b851c3a13b7") } > db.findAndReplaceDemo.insertOne({"UserId":NumberLong(101)}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2c969b64f4b851c3a13b8") } > db.findAndReplaceDemo.insertOne({"UserId":NumberLong(120)}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2c96cb64f4b851c3a13b9") } > db.findAndReplaceDemo.insertOne({"UserId":NumberLong(130)}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2c96eb64f4b851c3a13ba") }Following is the query to display all documents from a collection with the help of find() method ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
349 Views
You can use Date() along with $gte operator to find objects created last week. Here the curdate is as follows in my system −> new Date(); ISODate("2019-05-14T08:32:42.773Z")Let us first create a collection with documents −> db.findObectInLastWeekDemo.insertOne({"ShippingDate":new ISODate("2019-05-01")}); { "acknowledged" : true, "insertedId" : ObjectId("5cda7dc4bf3115999ed511e0") } > db.findObectInLastWeekDemo.insertOne({"ShippingDate":new ISODate("2019-05-02")}); { "acknowledged" : true, "insertedId" : ObjectId("5cda7dc4bf3115999ed511e1") } > db.findObectInLastWeekDemo.insertOne({"ShippingDate":new ISODate("2019-05-08")}); { "acknowledged" : true, "insertedId" : ObjectId("5cda7dc4bf3115999ed511e2") } > db.findObectInLastWeekDemo.insertOne({"ShippingDate":new ISODate("2019-05-07")}); { "acknowledged" : true, "insertedId" : ObjectId("5cda7dc4bf3115999ed511e3") } > db.findObectInLastWeekDemo.insertOne({"ShippingDate":new ISODate("2019-05-09")}); { "acknowledged" : true, "insertedId" : ObjectId("5cda7dc4bf3115999ed511e4") } > ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
358 Views
You can use dot(.) notation to find the document from sub array. Let us first create a collection with documents −> db.findDocumentDemo.insertOne( ... { ... "EmployeeDetails" : ... { ... "EmployeeAppraisalTime": ... ... [ ... ... {"EmployeeDesignation": "Developer", "Salary": 45000}, ... {"EmployeeDesignation": "Tester", "Salary": 30000}, ... {"EmployeeDesignation": "HR", "Salary": 22000}, ... {"EmployeeDesignation": "Accountant", "Salary": 18000} ... ] ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
131 Views
Let’s say, here we are incrementing StudentScores for MongoDB which is inside StudentDetails −... "StudentScores": { ... "StudentMathScore": 90, ... "StudentMongoDBScore": 78 ... }Let us first create a collection with documents −> db.embeddedValueIncrementDemo.insertOne( ... { ... "StudentDetails": { ... "StudentScores": { ... "StudentMathScore": 90, ... "StudentMongoDBScore": 78 ... } ... } ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5cd2b670345990cee87fd896") }Following is the query to display ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
230 Views
You can use $inc operator to increment. Let us first create a collection with documents −> db.addInUpdateFunctionDemo.insertOne({"PlayerName":"Chris", "PlayerScore":78}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2b3f4345990cee87fd893") } > db.addInUpdateFunctionDemo.insertOne({"PlayerName":"Robert", "PlayerScore":88}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2b3fc345990cee87fd894") } > db.addInUpdateFunctionDemo.insertOne({"PlayerName":"David", "PlayerScore":99}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2b407345990cee87fd895") }Following is the query to display all documents from a collection with the help of find() method −> db.addInUpdateFunctionDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd2b3f4345990cee87fd893"), "PlayerName" : "Chris", "PlayerScore" : 78 } { "_id" : ObjectId("5cd2b3fc345990cee87fd894"), "PlayerName" : "Robert", ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
89 Views
You can use getSiblingDB() from MongoDB for this using var keyword from JS −anyVariableName= db.getSiblingDB(‘yourDatabaseName’);Let us implement the above syntax in order to select database −> selectedDatabase = db.getSiblingDB('sample');This will produce the following output −SampleNow, insert some documents. Let’s say the collection is ‘selectDatabaseDemo’ −> db.selectDatabaseDemo.insertOne({"ClientName":"John Smith", "ClientAge":23}); { "acknowledged" : true, "insertedId" : ObjectId("5cda794b5667f1cce01d55ad") } > db.selectDatabaseDemo.insertOne({"ClientName":"Carol Taylor", "ClientAge":24}); { "acknowledged" : true, "insertedId" : ObjectId("5cda79565667f1cce01d55ae") }Display all documents from a collection with the help of find() method −db.selectDatabaseDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cda794b5667f1cce01d55ad"), "ClientName" : "John Smith", ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
117 Views
You need to use $set operator along with upsert:true. Let us first create a collection with documents −> db.updateWithUpsertDemo.insertOne({"StudentFirstName":"John", "StudentAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2a61c345990cee87fd890") } > db.updateWithUpsertDemo.insertOne({"StudentFirstName":"Larry", "StudentAge":23}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2a624345990cee87fd891") } > db.updateWithUpsertDemo.insertOne({"StudentFirstName":"David", "StudentAge":24}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2a62c345990cee87fd892") }Following is the query to display all documents from a collection with the help of find() method −> db.updateWithUpsertDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd2a61c345990cee87fd890"), "StudentFirstName" : "John", "StudentAge" : 21 } { "_id" : ObjectId("5cd2a624345990cee87fd891"), "StudentFirstName" ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
243 Views
You can use $where operator for this. Let us first create a collection with documents −>db.searchDocumentArrayIntegerDemo.insertOne({"StudentFirstName":"John", "StudentScores":[45, 78, 89, 90]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2a219345990cee87fd88c") } >db.searchDocumentArrayIntegerDemo.insertOne({"StudentFirstName":"Larry", "StudentScores":[45, 43, 34, 33]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2a22a345990cee87fd88d") } >db.searchDocumentArrayIntegerDemo.insertOne({"StudentFirstName":"Chris", "StudentScores":[]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2a23c345990cee87fd88e") } >db.searchDocumentArrayIntegerDemo.insertOne({"StudentFirstName":"David", "StudentScores":[99]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2a24d345990cee87fd88f") }Following is the query to display all documents from a collection with the help of find() method −> db.searchDocumentArrayIntegerDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd2a219345990cee87fd88c"), "StudentFirstName" : ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
149 Views
You can use dot(.) notation along with array index to get record beginning with specific element. Let us first create a collection with documents −>db.arrayStartsWithElementDemo.insertOne({"PlayerName":"Chris", "PlayerScore":[780, 9000, 456, 789, 987]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd29fed345990cee87fd889") } >db.arrayStartsWithElementDemo.insertOne({"PlayerName":"Robert", "PlayerScore":[890, 670, 890, 54646, 42424]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2a00c345990cee87fd88a") } >db.arrayStartsWithElementDemo.insertOne({"PlayerName":"David", "PlayerScore":[909090, 896555, 3344433, 78900]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2a025345990cee87fd88b") }Following is the query to display all documents from a collection with the help of find() method −> db.arrayStartsWithElementDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd29fed345990cee87fd889"), ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
142 Views
You can use aggregate framework for this. Let us first create a collection with documents −>db.exactPositionDemo.insertOne({"StudentName":"John", "StudentScores":[78, 98, 56, 45, 89]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd29a1c345990cee87fd883") }Following is the query to display all documents from a collection with the help of find() method −> db.exactPositionDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd29a1c345990cee87fd883"), "StudentName" : "John", "StudentScores" : [ 78, 98, 56, 45, 89 ] }Case 1 − Query to aggregate a $slice to get an ... Read More