- 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)
876 Views
To pull multiple objects from an array, you can use $pull operator. Let us first create a collection with documents −> db.pullMultipleObjectsDemo.insertOne( ... { ... "ClientId" : "100", ... "ClientName" : "John", ... "ClientPersonalDetails" : [ ... { ... "ClientCountryName" : "US", ... "ClientProjectName" : "Online Book Store", ... ... }, ... { ... "ClientCountryName" : "AUS", ... ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
997 Views
You need to use changeUserPassword() to change a user’s password. Let us first create a user with some roles. Following is the query to create a user in MongoDB −> use admin switched to db admin > db.createUser( ... { ... user: "Chris", ... pwd: "chris", ... roles: [ { role: "readWrite", db: "test" } ] ... } ... ); Successfully added user: { "user" : "Chris", "roles" : [ { "role" : "readWrite", "db" : ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
1K+ Views
You can use find() for this. Let us first create a collection with documents −> db.findInDictionaryDemo.insertOne( ... { ... "_id":101, ... "AllCustomerDetails": ... { ... "SomeCustomerDetail1": ... { ... "CustomerName1":"John Doe", ... "CustomerName2":"John Smith" ... }, ... "SomeCustomerDetail2": ... { ... "CustomerName1":"Carol Taylor", ... "CustomerName2":"David Miller" ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
318 Views
You need to find the document and after that you need to use update to toggle query. Let us first create a collection with documents −> db.toggleDemo.insertOne({"CustomerName":"John Smith", "CustomerAge":28, "isMarried":true}); { "acknowledged" : true, "insertedId" : ObjectId("5cc7be138f9e6ff3eb0ce43b") } > db.toggleDemo.insertOne({"CustomerName":"David Miller", "CustomerAge":25, "isMarried":false}); { "acknowledged" : true, "insertedId" : ObjectId("5cc7be2e8f9e6ff3eb0ce43c") }Following is the query to display all documents from a collection with the help of find() method −> db.toggleDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cc7be138f9e6ff3eb0ce43b"), "CustomerName" : "John Smith", "CustomerAge" : 28, "isMarried" : true } { "_id" : ObjectId("5cc7be2e8f9e6ff3eb0ce43c"), "CustomerName" : "David Miller", "CustomerAge" : 25, ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
803 Views
You can use regular expression along with $not operator to ignore a specific character and display rest of them. Let us first create a collection with documents −> db.regexDemo.insertOne({"CustomerId":"Customer#1234", "CustomerName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5cc7428f8f9e6ff3eb0ce436") } > db.regexDemo.insertOne({"CustomerId":"Customer5678", "CustomerName":"Robert"}); { "acknowledged" : true, "insertedId" : ObjectId("5cc7429e8f9e6ff3eb0ce437") } > db.regexDemo.insertOne({"CustomerId":"Customer#777", "CustomerName":"Carol"}); { "acknowledged" : true, "insertedId" : ObjectId("5cc742ae8f9e6ff3eb0ce438") } > db.regexDemo.insertOne({"CustomerId":"Customer777", "CustomerName":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5cc742bc8f9e6ff3eb0ce439") }Following is the query to display all documents from a collection with the help of find() method −> db.regexDemo.find().pretty();This will produce the ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
102 Views
To get the same result like AND in MongoDB, use the $all operator. Let us first create a collection with documents −> db.andQueryDemo.insertOne({"StudentName":"Carol Taylor", "FavouriteSubject":["C", "Java", "MongoDB", "MySQL"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cc73e7a8f9e6ff3eb0ce433") } > db.andQueryDemo.insertOne({"StudentName":"David Miller", "FavouriteSubject":["C++", "Java", "MongoDB", "SQL Server"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cc73ea48f9e6ff3eb0ce434") } > db.andQueryDemo.insertOne({"StudentName":"Carol Taylor", "FavouriteSubject":["Python", "PL/SQL"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cc73ed38f9e6ff3eb0ce435") }Following is the query to display all documents from a collection with the help of find() method −> db.andQueryDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cc73e7a8f9e6ff3eb0ce433"), ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
316 Views
To sum every field in a sub document, use aggregate framework. Let us first create a collection with documents −> db.sumEveryFieldDemo.insertOne( ... { ... "_id":101, ... "PlayerDetails": [ ... {"PlayerName":"John", "PlayerScore":1000}, ... {"PlayerName":"Carol", "PlayerScore":2000}, ... {"PlayerName":"Sam", "PlayerScore":3000} ... ] ... } ... ); { "acknowledged" : true, "insertedId" : 101 }Following is the query to display all documents from a collection with the help of find() method −> db.sumEveryFieldDemo.find().pretty();This will produce the following output −{ "_id" : 101, "PlayerDetails" : [ { "PlayerName" : "John", ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
1K+ Views
To check if value exists for a field in a MongoDB document, you can use find() along with $exists operator. Let us first create a collection with documents −> db.checkIfValueDemo.insertOne({"PlayerName":"John Smith", "PlayerScores":[5000, 98595858, 554343]}); { "acknowledged" : true, "insertedId" : ObjectId("5cc6f507af8e7a4ca6b2ad98") } > db.checkIfValueDemo.insertOne({"PlayerName":"John Doe", "PlayerScores":[]}); { "acknowledged" : true, "insertedId" : ObjectId("5cc6f512af8e7a4ca6b2ad99") } > db.checkIfValueDemo.insertOne({"PlayerName":"Carol Taylor", "PlayerScores":[7848474, 8746345353]}); { "acknowledged" : true, "insertedId" : ObjectId("5cc6f521af8e7a4ca6b2ad9a") } > db.checkIfValueDemo.insertOne({"PlayerName":"David Miller", "PlayerScores":[]}); { "acknowledged" : true, "insertedId" : ObjectId("5cc6f531af8e7a4ca6b2ad9b") }Following is the query to display all documents from a collection with the help ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
135 Views
Yes, you can set a variable collection name in MongoDB shell using JavaScript. Let us first create a collection with documents −> db.employeeInformation.insertOne({"EmployeeName":"John Smith", "EmployeeAge":24, "EmployeeSalary":450000}); { "acknowledged" : true, "insertedId" : ObjectId("5cc6d06baf8e7a4ca6b2ad97") }Following is the query to display all documents from a collection with the help of find() method −> db.employeeInformation.find();This will produce the following output −{ "_id" : ObjectId("5cc6d06baf8e7a4ca6b2ad97"), "EmployeeName" : "John Smith", "EmployeeAge" : 24, "EmployeeSalary" : 450000 }Here is the query to set variable collection name in MongoDB shell using JavaScript.Case 1 − Set variable with varThe query is as follows −> var status=db.employeeInformation; ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
9K+ Views
First open the CMD and then reach the BIN directory of MongoDB. The screenshot to open CMD prompt is as follows.Above we have reached the RUN dialog by pressing START and then typing RUN and ENTER.Now, type CMD and press OK button to get the command line. The screenshot is as follows −Reach the BIN directory of MongoDB. Following is how to reach the BIN −Use the query mongo –version. The screenshot of the query is as follows −Above displays that our current MongoDB version is v4.0.5.