- 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
320 Views
To aggregate multiple arrays into a single array, use $project in MongoDB. Let us create a collection with documents −> db.demo119.insertOne( ... { ... "_id": 101, ... "WebDetails": [ ... { ... "ImagePath": "/all/image1", ... "isCorrect": "false" ... }, ... { ... "ImagePath": "/all/image2", ... "isCorrect": "true" ... } ... ... Read More
854 Views
Let us first create a collection with documents −> db.demo118.insertOne( ... { ... "Id" : "101", ... "Name" : "Chris", ... "Subjects" : [ ... "MySQL", ... "MongoDB", ... "Java" ... ], ... "Details" : [ ... { ... "Name" : "David", ... S:"MongoDB" ... }, ... { ... Read More
322 Views
To aggregate sum of values in a list of dictionaries, use $sum along with aggregate(). Let us create a collection with documents −> db.demo117.insertOne( ... { ... ID:101, ... Details:[ ... { ... Name:'Chris', ... Value1:20, ... Value2:30, ... Value3:10 ... }, ... { ... Name:'David', ... ... Read More
78 Views
To find only a single document, use findOne() in MongoDB. Let us create a collection with documents −> db.demo116.insertOne({"EmployeeId":101, "EmployeeName":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2eff98d8f64a552dae635b") } > db.demo116.insertOne({"EmployeeId":102, "EmployeeName":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2eff9fd8f64a552dae635c") } > db.demo116.insertOne({"EmployeeId":103, "EmployeeName":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2effa5d8f64a552dae635d") } > db.demo116.insertOne({"EmployeeId":102, "EmployeeName":"Mike"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2effb7d8f64a552dae635e") }Display all documents from a collection with the help of find() method −> db.demo116.find();This will produce the following output −{ "_id" : ObjectId("5e2eff98d8f64a552dae635b"), "EmployeeId" : 101, "EmployeeName" : "John" } { "_id" ... Read More
401 Views
For this, use find() along with update(). Let us create a collection with documents −> db.demo115.insertOne({"LastName":"Brown"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2efe9bd8f64a552dae635a") }Display all documents from a collection with the help of find() method −> db.demo115.find();This will produce the following output −{ "_id" : ObjectId("5e2efe9bd8f64a552dae635a"), "LastName" : "Brown" }Following is the query to update field and modify the data currently in column −> db.demo115.find({"LastName":"Brown"}).forEach(function(d) { ... db.demo115.update({_id: d._id}, {$set: {LastName: 'Hello ' + d.LastName}}); ... })Display all documents from a collection with the help of find() method −> db.demo115.find();This will produce the following output −{ "_id" : ... Read More
105 Views
To find maximum score, use GROUP() to group documents in a collection. Let us create a collection with documents −> db.demo114.insertOne({"Score":60, "Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2efc57d8f64a552dae6354") } > db.demo114.insertOne({"Score":87, "Nam+e":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2efc5ad8f64a552dae6355") } > db.demo114.insertOne({"Score":45, "Name":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2efc5dd8f64a552dae6356") } > db.demo114.insertOne({"Score":67, "Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2efc68d8f64a552dae6357") } > db.demo114.insertOne({"Score":38, "Name":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2efc74d8f64a552dae6358") }Display all documents from a collection with the help of find() method −> db.demo114.find();This will produce the ... Read More
1K+ Views
To create views in MongoDB, use createView(). Let us create a collection with documents −> db.demo113.insertOne( ... { _id: 1, StudentId: "101", "Details": { Name: "Chris", Age: 21 }, Subject: "MySQL" } ... ); { "acknowledged" : true, "insertedId" : 1 }Display all documents from a collection with the help of find() method −> db.demo113.find().pretty();This will produce the following output −{ "_id" : 1, "StudentId" : "101", "Details" : { "Name" : "Chris", "Age" : 21 }, "Subject" : "MySQL" }Following is the query to create views in MongoDB ... Read More
224 Views
To update, you need to use update() for the field whose collection is set with capped: true. Let us create a collection with documents −> db.createCollection("Demo112", { capped : true, size : 14, max : 3 } ); { "ok" : 1 } > db.demo112.insertOne({"Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2ef47a9fd5fd66da21447e") } > db.demo112.insertOne({"Name":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2ef47e9fd5fd66da21447f") } > db.demo112.insertOne({"Name":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2ef4919fd5fd66da214480") }Display all documents from a collection with the help of find() method −> db.demo112.find();This will produce the following output −{ "_id" : ... Read More
300 Views
For this, use aggregate() in MongoDB. In that, use $slice to slice array inside array. Let us create a collection with documents −> db.demo111.insertOne( ... { ... "_id" : 101, ... "Name" : "Chris", ... "Details" : [ ... { ... "_id" : 101, ... "Score" : 78, ... "Subjects" : [ ... { ... ... Read More
136 Views
To update data in MongoDB, use update(). Let us create a collection with documents −> db.demo110.insertOne({"Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2eeb949fd5fd66da21447b") } > db.demo110.insertOne({"Name":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2eeb9f9fd5fd66da21447c") } > db.demo110.insertOne({"Name":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5e2eeba39fd5fd66da21447d") }Display all documents from a collection with the help of find() method −> db.demo110.find();This will produce the following output −{ "_id" : ObjectId("5e2eeb949fd5fd66da21447b"), "Name" : "Chris" } { "_id" : ObjectId("5e2eeb9f9fd5fd66da21447c"), "Name" : "David" } { "_id" : ObjectId("5e2eeba39fd5fd66da21447d"), "Name" : "Bob" }Following is the query to update data in MongoDB ... Read More