
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
AmitDiwan has Published 10744 Articles

AmitDiwan
823 Views
Use the updateMany() function to update all documents that match the filter criteria. Let us create a collection with documents −> db.demo476.insertOne({_id:1, "Name":"Chris"}); { "acknowledged" : true, "insertedId" : 1 } > db.demo476.insertOne({_id:2, "Name":"David"}); { "acknowledged" : true, "insertedId" : 2 } > db.demo476.insertOne({_id:3, "Name":"Bob"}); { "acknowledged" : true, "insertedId" ... Read More

AmitDiwan
1K+ Views
To check the existence of multiple fields, use $exists along with $and. Let us create a collection with documents −> db.demo475.insertOne({"StudentFirstName":"Chris", "StudentAge":23});{ "acknowledged" : true, "insertedId" : ObjectId("5e80c113b0f3fa88e2279088") } > db.demo475.insertOne({"StudentFirstName":"Bob", "StudentAge":21, "StudentCountryName":"US"});{ "acknowledged" : true, "insertedId" : ObjectId("5e80c127b0f3fa88e2279089") } > db.demo475.insertOne({"StudentFirstName":"David", "StudentAge":22});{ "acknowledged" : ... Read More

AmitDiwan
237 Views
To return a specific data, use findOne() in MongoDB. The findOne() method returns one document that satisfies the specified query criteria on the collection Let us create a collection with documents −> db.demo473.insertOne( ... { ... "_id" : new ObjectId(), ... "Name" : "Chris", ... "details" : ... Read More

AmitDiwan
273 Views
To find documents where a field is equal to given integer, use find(). Let us create a collection with documents −> db.demo472.insertOne({"Project_Id":-101, "ProjectName":"Online Customer Tracking"});{ "acknowledged" : true, "insertedId" : ObjectId("5e80586cb0f3fa88e227907a") } > db.demo472.insertOne({"Project_Id":101, "ProjectName":"Online Banking System"});{ "acknowledged" : true, "insertedId" : ObjectId("5e805884b0f3fa88e227907b") } > db.demo472.insertOne({"Project_Id":102, ... Read More

AmitDiwan
369 Views
To remove primary key in MongoDB, set _id value to 0 i.e. set the field you want to exclude as 0 in find(). Let us create a collection with documents −> db.demo471.insertOne({"ClientId":101, "ClientName":"Chris"});{ "acknowledged" : true, "insertedId" : ObjectId("5e805711b0f3fa88e2279077") } > db.demo471.insertOne({"ClientId":102, "ClientName":"Bob"});{ "acknowledged" : true, ... Read More

AmitDiwan
227 Views
To get all the ages that are ints from records having string and int ages records, use $type. The $type in MongoDB $type selects documents where the value of the field is an instance of the specified BSON type.Let us create a collection with documents −> db.demo470.insertOne({"Age":23});{ "acknowledged" : ... Read More

AmitDiwan
67 Views
To find documents containing a particular value with Regular Expressions, use MongoDB $regex. Let us create a collection with documents −> db.demo469.insertOne({"StudentName":"John Doe"});{ "acknowledged" : true, "insertedId" : ObjectId("5e80532fb0f3fa88e227906b") } > db.demo469.insertOne({"StudentName":"Chris Brown"});{ "acknowledged" : true, "insertedId" : ObjectId("5e80533ab0f3fa88e227906c") } > db.demo469.insertOne({"StudentName":"John Smith"});{ "acknowledged" : ... Read More

AmitDiwan
300 Views
To find a MongoDB record that is two level deep, loop inside MongoDB $where. Let us create a collection with documents −> db.demo468.insertOne( ... { ... "_id" : new ObjectId(), ... "FirstPosition" : { ... "StudentName" : "Chris", ... "StudentAge" : 23 ... }, ... "SecondPosition" : { ... Read More

AmitDiwan
740 Views
To delete an item from an object in MongoDB, use $unset. Let us create a collection with documents −> db.demo467.insertOne( ... { ... _id:101, ... "Information":{"Name":"Chris"} ... } ... ); { "acknowledged" : true, "insertedId" : 101 } > db.demo467.insertOne( ... { ... _id:102, ... "Information":{"Name":"David"} ... } ... ); ... Read More

AmitDiwan
642 Views
The $group in MongoDB is used to group input documents by the specified _id expression. Let us create a collection with documents −> db.demo466.insertOne( ... { ... ... "ProductPrice" :150, ... "ProductQuantity" : 1, ... "ProductName" : "Product-1", ... "ActualAmount" :110, ... "ProductProfit" : 40, ... "ProductId" : 1 ... ... Read More