- 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
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
109 Views
For this, use MongoDB $substr. Let us first create a collection with documents −> dblimitTheNumberOfCharactersDemoinsertOne({"Title":"MongoDB is No SQL database"}); { "acknowledged" : true, "insertedId" : ObjectId("5cf23013b64a577be5a2bc0e") } > dblimitTheNumberOfCharactersDemoinsertOne({"Title":"MySQL is a relational database"}); { "acknowledged" : true, "insertedId" : ObjectId("5cf2302db64a577be5a2bc0f") } Following is the query to display all documents from a collection with the help of find() method −> dblimitTheNumberOfCharactersDemofind()pretty();This will produce the following document −{ "_id" : ObjectId("5cf23013b64a577be5a2bc0e"), "Title" : "MongoDB is No SQL database" } { "_id" : ObjectId("5cf2302db64a577be5a2bc0f"), "Title" : "MySQL is a relational database" }Following is the ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
186 Views
You can use pop() for this. Let us first create a collection with documents −> db.persistChangeDemo.insertOne({"Name" : "Larry", "CreditScore": [500, 700, 760, 100]}); { "acknowledged" : true, "insertedId" : ObjectId("5cdfc52cbf3115999ed51203") }Following is the query to display all documents from a collection with the help of find() method −> db.persistChangeDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cdfc52cbf3115999ed51203"), "Name" : "Larry", "CreditScore" : [ 500, 700, 760, 100 ] }Following is the query to pop a value −> myDocument.CreditScore.pop(); 100Let us save ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
959 Views
We will use printjson() for this. Let us first create a collection with documents −> dbprintResultScriptDemoinsertOne({"StudentName":"John", "StudentAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5cf22c02b64a577be5a2bc0b") } > dbprintResultScriptDemoinsertOne({"StudentName":"Carol", "StudentAge":20}); { "acknowledged" : true, "insertedId" : ObjectId("5cf22c09b64a577be5a2bc0c") } > dbprintResultScriptDemoinsertOne({"StudentName":"David", "StudentAge":19}); { "acknowledged" : true, "insertedId" : ObjectId("5cf22c11b64a577be5a2bc0d") }Following is the query to display all documents from a collection with the help of find() method −> dbprintResultScriptDemofind();This will produce the following document −{ "_id" : ObjectId("5cf22c02b64a577be5a2bc0b"), "StudentName" : "John", "StudentAge" : 21 } { "_id" : ObjectId("5cf22c09b64a577be5a2bc0c"), "StudentName" : "Carol", "StudentAge" : 20 } { "_id" ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
299 Views
For this, use the $addToSet operator. Let us first create a collection with documents −> db.findDocumentWithCommonFieldsDemo.insertOne( { "UserId":1, "UserName":"Carol" } ); { "acknowledged" : true, "insertedId" : ObjectId("5cdf8ebebf3115999ed51200") } > db.findDocumentWithCommonFieldsDemo.insertOne( { "UserId":2, "UserName":"David" } ); { "acknowledged" : true, "insertedId" : ObjectId("5cdf8ebebf3115999ed51201") } > > db.findDocumentWithCommonFieldsDemo.insertOne( { "UserId":1, "UserName":"Sam" } ); { "acknowledged" : true, "insertedId" : ObjectId("5cdf8ebebf3115999ed51202") }Following is the query to display all documents from a collection ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
128 Views
To compare multiple properties, use the $where operator. Let us first create a collection with documents −> dbcomparingMultiplePropertiesDemoinsertOne({"Values":[10, 70, 60]}); { "acknowledged" : true, "insertedId" : ObjectId("5cf228fcb64a577be5a2bc0a") }Following is the query to display all documents from a collection with the help of find() method −> dbcomparingMultiplePropertiesDemofind()pretty();This will produce the following document −{ "_id" : ObjectId("5cf228fcb64a577be5a2bc0a"), "Values" : [ 10, 70, 60 ] }Case 1: If condition becomes true then you will get an array otherwise nothing will get displayed Following is the query to compare multiple ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
82 Views
Let us first create a collection with documents −> dbworkingOfRegularExpressionDemoinsertOne({ "StudentDetails" : { "StudentName" : "John" }, "StudentAge":21 }); { "acknowledged" : true, "insertedId" : ObjectId("5cf227acb64a577be5a2bc07") } > dbworkingOfRegularExpressionDemoinsertOne({ "StudentDetails" : { "StudentName" : "JOHN" }, "StudentAge":19 }); { "acknowledged" : true, "insertedId" : ObjectId("5cf227b8b64a577be5a2bc08") } > dbworkingOfRegularExpressionDemoinsertOne({ "StudentDetails" : { "StudentName" : "Carol" }, "StudentAge":20 }); { "acknowledged" : true, "insertedId" : ObjectId("5cf227c2b64a577be5a2bc09") }Following is the query to display all documents from a collection with the help of find() method −> dbworkingOfRegularExpressionDemofind();This will produce the following document −{ "_id" : ObjectId("5cf227acb64a577be5a2bc07"), "StudentDetails" : ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
131 Views
To delete specific record, use $pull operator. Let us first create a collection with documents −> dbdeletingSpecificRecordDemoinsertOne( { "StudentDetails": [ { "StudentName": "John", "StudentSubjectDetails": [ { "Subject": "MongoDB", "Marks":45 }, { "Subject": ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
162 Views
Use aggregation for this and add the values to an array using the $group and $addToSet operatorLet us first create a collection with documents −> dbspecifyReturnFormatDemoinsertOne({"Subject":"MongoDB"}); { "acknowledged" : true, "insertedId" : ObjectId("5cefd364ef71edecf6a1f6c0") } > dbspecifyReturnFormatDemoinsertOne({"Subject":"MySQL"}); { "acknowledged" : true, "insertedId" : ObjectId("5cefd369ef71edecf6a1f6c1") } > dbspecifyReturnFormatDemoinsertOne({"Subject":"SQL Server"}); { "acknowledged" : true, "insertedId" : ObjectId("5cefd36fef71edecf6a1f6c2") }Following is the query to display all documents from a collection with the help of find() method −> dbspecifyReturnFormatDemofind();Output{ "_id" : ObjectId("5cefd364ef71edecf6a1f6c0"), "Subject" : "MongoDB" } { "_id" : ObjectId("5cefd369ef71edecf6a1f6c1"), "Subject" : "MySQL" } { "_id" : ObjectId("5cefd36fef71edecf6a1f6c2"), "Subject" : ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
183 Views
Use $elemMatch fir this with $setLet us first create a collection with documents −> dbkeyValueDemoinsertOne( { "_id" : new ObjectId(), "CustomerDetails" : [ { "Name" : "Chris", "Age" :24, }, { "Name" : "Robert", "Age" :29, }, { "Name" : "David", ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
110 Views
Yes, using map(). Let us first create a collection with documents −> dblistOfSpecificValuesDemoinsertOne({"StudentName":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5cefcc8fef71edecf6a1f6bb") } > dblistOfSpecificValuesDemoinsertOne({"StudentName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5cefcc94ef71edecf6a1f6bc") } > dblistOfSpecificValuesDemoinsertOne({"StudentName":"Robert"}); { "acknowledged" : true, "insertedId" : ObjectId("5cefcc98ef71edecf6a1f6bd") } > dblistOfSpecificValuesDemoinsertOne({"StudentName":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5cefcc9cef71edecf6a1f6be") }Following is the query to display all documents from a collection with the help of find() method −> dblistOfSpecificValuesDemofind();Output{ "_id" : ObjectId("5cefcc8fef71edecf6a1f6bb"), "StudentName" : "John" } { "_id" : ObjectId("5cefcc94ef71edecf6a1f6bc"), "StudentName" : "Chris" } { "_id" : ObjectId("5cefcc98ef71edecf6a1f6bd"), "StudentName" : "Robert" } ... Read More