
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
230 Views
To convert collection to capped, use runCommand(). It provides a helper to run specified database commands. Let us first create a collection with documents −> db.demo416.insertOne({"StudentName":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e723a7bb912067e57771adf") } > db.demo416.insertOne({"StudentName":"Mike"}); { "acknowledged" : true, "insertedId" : ObjectId("5e723a81b912067e57771ae0") } > db.demo416.insertOne({"StudentName":"Sam"}); ... Read More

AmitDiwan
7K+ Views
To select specific columns, you can ignore the rest of them i.e. to hide those columns, set them to 0. Let us first create a collection with documents −> db.demo415.insertOne({"ClientName":"Robert", "ClientCountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5e72329db912067e57771adc") } > db.demo415.insertOne({"ClientName":"David", "ClientCountryName":"UK"}); { "acknowledged" : true, ... Read More

AmitDiwan
842 Views
To find by _id on an array of objects, use aggregation and avoid using find(). Let us first create a collection with documents −> db.demo414.insertOne( ... { ... "_id": "110", ... "details":[ ... { ... ... Read More

AmitDiwan
917 Views
Achieve this with aggregation pipeline. Let us first create a collection with documents −> db.demo413.insertOne( ... { ... "_id": "101", ... "details": { ... "Info1": { ... Name:"Chris", ... ... Read More

AmitDiwan
256 Views
Let us create a collection with documents −> db.demo411.aggregate( ... [ ... {$project : { ... _id : 0, ... Information : {$map : {input : "$Information", as : "out", in : ["$$out.Name1", "$$out.Name2"]}} ... ... Read More

AmitDiwan
931 Views
Let us create a collection with documents −> db.demo411.insertOne( ... { ... "Information" : [ ... { ... "Name1" : "Chris", ... "Name2" : "David" ... ... Read More

AmitDiwan
407 Views
To remove elements, use $pull and for such conditions, use $ne. The $ne in MongoDB is used to select the documents where the value of the field is not equal to the specified value.Let us create a collection with documents −> db.demo410.insertOne( ... { ... details: ... Read More

AmitDiwan
212 Views
To find documents with a specific string, use find() and in that search for a string with regex. Let us create a collection with documents −> db.demo409.insertOne({"Name":"John Doe"}); { "acknowledged" : true, "insertedId" : ObjectId("5e70e4e515dc524f7022767c") } > db.demo409.insertOne({"Name":"Chris Brown"}); { "acknowledged" : true, "insertedId" : ObjectId("5e70e4ec15dc524f7022767d") ... Read More

AmitDiwan
548 Views
To get a query plan in MongoDB, use explain(). The $explain operator gives information on the query plan.Let us create a collection with documents −> db.demo408.insertOne({"Value":50}); { "acknowledged" : true, "insertedId" : ObjectId("5e70e3a115dc524f70227678") } > db.demo408.insertOne({"Value":20}); { "acknowledged" : true, "insertedId" : ObjectId("5e70e3a715dc524f70227679") } > db.demo408.insertOne({"Value":45}); ... Read More

AmitDiwan
135 Views
For this, use $setIsSubset in MongoDB. Let us create a collection with documents −> db.demo407.insertOne( ... { ... Name:"Chris", ... "details" : [ ... { ... id:100 ... }, ... Read More