- 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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
493 Views
The fastest way is to use replaceOne() in MongoDB. Let us create a collection with documents −> db.demo431.insertOne({"Name":"Chris", "Age":32}); { "acknowledged" : true, "insertedId" : ObjectId("5e770ba6bbc41e36cc3cae89") } > db.demo431.insertOne({"Name":"David", "Age":31}); { "acknowledged" : true, "insertedId" : ObjectId("5e770bacbbc41e36cc3cae8a") } > db.demo431.insertOne({"Name":"John", "Age":24}); { "acknowledged" : true, "insertedId" : ObjectId("5e770bb3bbc41e36cc3cae8b") } > db.demo431.insertOne({"Name":"Bob", "Age":22}); { "acknowledged" : true, "insertedId" : ObjectId("5e770bb8bbc41e36cc3cae8c") }Display all documents from a collection with the help of find() method −> db.demo431.find();This will produce the following output −{ "_id" : ObjectId("5e770ba6bbc41e36cc3cae89"), "Name" : "Chris", "Age" : 32 } { "_id" : ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
139 Views
Let us create a collection with documents −> db.demo430.insertOne( ... { ... "details": [ ... { ... "Name":"Chris" ... } , ... {"Name":"David"}, ... {"Name":"Adam"}, ... {"Name":"Bob"} ... ... ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e7702ddbbc41e36cc3cae88") }Display all documents from a collection with the help of find() method −> db.demo430.find();This will produce the following output −{ "_id" : ObjectId("5e7702ddbbc41e36cc3cae88"), "details" : [ { "Name" : "Chris" }, { "Name" : "David" }, { "Name" : "Adam" }, { "Name" : "Bob" } ] }Following is the query to group records −> db.demo430.aggregate([{ "$group" : { "_id" : {"Name" : "$details.Name"}}}]);This will produce the following output −{ "_id" : { "Name" : [ "Chris", "David", "Adam", "Bob" ] } }
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
544 Views
For new field, use $addFields in MongoDB. The $addFields is used to add new fields to documents. Let us create a collection with documents −> db.demo429.insertOne( ... { ... "_id": 101, ... "Value": 3, ... "details": [ ... { ... "Age": 29, ... "Value": 3, ... "details1": [ ... 1, ... 2, ... ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
365 Views
For multiple write operations, use bulkWrite() in MongoDB. Let us create a collection with documents −> db.demo428.insertOne({ "Name" : "Chris", "Age" : 21 }); { "acknowledged" : true, "insertedId" : ObjectId("5e75f428bbc41e36cc3cae83") } > db.demo428.insertOne({ "Name" : "Chris", "Age" : 23 }); { "acknowledged" : true, "insertedId" : ObjectId("5e75f429bbc41e36cc3cae84") } > db.demo428.insertOne({ "Name" : "David", "Age" : 22 }); { "acknowledged" : true, "insertedId" : ObjectId("5e75f42abbc41e36cc3cae85") } > db.demo428.insertOne({ "Name" : "David", "Age" : 21 }); { "acknowledged" : true, "insertedId" : ObjectId("5e75f42abbc41e36cc3cae86") }Display all documents from a collection with the help of ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
439 Views
To update, use UPDATE() and $set. Let us create a collection with documents −> db.demo427.insertOne({"StudentId":101, "StudentName":"Chris Brown"}); { "acknowledged" : true, "insertedId" : ObjectId("5e75e711bbc41e36cc3cae75") } > db.demo427.insertOne({"StudentId":102, "StudentName":"David Miller"}); { "acknowledged" : true, "insertedId" : ObjectId("5e75e71abbc41e36cc3cae76") } > db.demo427.insertOne({"StudentId":103, "StudentName":"John Smith"}); { "acknowledged" : true, "insertedId" : ObjectId("5e75e725bbc41e36cc3cae77") } > db.demo427.insertOne({"StudentId":104, "StudentName":"Carol Taylor"}); { "acknowledged" : true, "insertedId" : ObjectId("5e75e733bbc41e36cc3cae78") }Display all documents from a collection with the help of find() method −> db.demo427.find();This will produce the following output −{ "_id" : ObjectId("5e75e711bbc41e36cc3cae75"), "StudentId" : 101, "StudentName" : "Chris Brown" } { ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
143 Views
Use $eq operator along with find() to match ID and fetch documents. The $eq specifies equality condition. It matches documents where the value of a field equals the specified value.Let us create a collection with documents −> db.demo426.insert({"Ids":["110", "120", "101"]}); WriteResult({ "nInserted" : 1 }) > db.demo426.insert({"Ids":["100", "201", "401"]}); WriteResult({ "nInserted" : 1 }) > db.demo426.insert({"Ids":["501", "600", "700"]}); WriteResult({ "nInserted" : 1 })Display all documents from a collection with the help of find() method −> db.demo426.find().pretty();This will produce the following output −{ "_id" : ObjectId("5e75e50fbbc41e36cc3cae72"), "Ids" : [ "110", "120", ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
To upsert many documents, use UPSERT() with UPDATE(). Let us create a collection with documents −> db.demo425.insertOne({"Name":"Chris", "Age":21}); { "acknowledged" : true, "insertedId" : ObjectId("5e74ee4fbbc41e36cc3cae6c") } > db.demo425.insertOne({"Name":"David", "Age":23}); { "acknowledged" : true, "insertedId" : ObjectId("5e74ee56bbc41e36cc3cae6d") } > db.demo425.insertOne({"Name":"Chris", "Age":21}); { "acknowledged" : true, "insertedId" : ObjectId("5e74ee57bbc41e36cc3cae6e") } > db.demo425.insertOne({"Name":"Chris", "Age":21}); { "acknowledged" : true, "insertedId" : ObjectId("5e74ee5cbbc41e36cc3cae6f") }Display all documents from a collection with the help of find() method −> db.demo425.find();This will produce the following output −{ "_id" : ObjectId("5e74ee4fbbc41e36cc3cae6c"), "Name" : "Chris", "Age" : 21 } { "_id" : ObjectId("5e74ee56bbc41e36cc3cae6d"), ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
195 Views
To extract a MongoDB document with a specific string, use $match in MongoDB. Let us create a collection with documents −> db.demo424.insert( ... { ... ... "Information" : [ ... { ... id:10, ... Name:"Chris" ... }, ... { ... id:11, ... Name:"David" ... } ... ] ... } ... ) WriteResult({ ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
123 Views
To speed up the $group phase, use $group along with aggregation. Let us see an example and create a collection with documents −> db.demo423.insertOne({"Information":[101, 110, 87, 110, 98, 115, 101, 115, 89, 115]}); { "acknowledged" : true, "insertedId" : ObjectId("5e73a60e9822da45b30346e6") }Display all documents from a collection with the help of find() method −> db.demo423.find();This will produce the following output −{ "_id" : ObjectId("5e73a60e9822da45b30346e6"), "Information" : [ 101, 110, 87, 110, 98, 115, 101, 115, 89, 115 ] }Following is the query to speed up $group phase in aggregation −> db.demo423.aggregate([ ... { ... $project: ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
621 Views
For exact match, set the values to be matched inside MongoDB $in(). Let us first create a collection with documents −> db.demo422.insertOne({"Name":"Chris", "Marks":34}); { "acknowledged" : true, "insertedId" : ObjectId("5e73a4059822da45b30346e1") } > db.demo422.insertOne({"Name":"Chris", "Marks":56}); { "acknowledged" : true, "insertedId" : ObjectId("5e73a40a9822da45b30346e2") } > db.demo422.insertOne({"Name":"David", "Marks":78}); { "acknowledged" : true, "insertedId" : ObjectId("5e73a4149822da45b30346e3") } > db.demo422.insertOne({"Name":"Sam", "Marks":45}); { "acknowledged" : true, "insertedId" : ObjectId("5e73a41e9822da45b30346e4") } > db.demo422.insertOne({"Name":"David", "Marks":89}); { "acknowledged" : true, "insertedId" : ObjectId("5e73a4239822da45b30346e5") }Display all documents from a collection with the help of find() method −> db.demo422.find();This will produce ... Read More