
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
3K+ Views
To create index in the background, use createIndex() method and set “background: true” as in the below syntax −db.yourCollectionName.createIndex({"yourFieldName1":1, "yourFieldName2":1}, {background: true} );Let us implement the above syntax in order to create index and set background −> db.indexCreationDemo.createIndex({"StudentName":1, "StudentAge":1}, {background: true} ); { "createdCollectionAutomatically" : true, "numIndexesBefore" : ... Read More

AmitDiwan
110 Views
The collation introduced in version MongoDB 3.4. Maybe, you implemented collation in a previous version.For our example, we are using MongoDB version 4.0.5. Following is the query to check the current version on system −> db.version()This will produce the following output −4.0.5Let us first create a collection with documents −> ... Read More

AmitDiwan
201 Views
To calculate average, use aggregate along with $avg. Let us first create a collection with documents −> db.calculateAverage.insertOne({'Value':[10, 20, 80]}); { "acknowledged" : true, "insertedId" : ObjectId("5e0383e3f5e889d7a51994dc") } > db.calculateAverage.insertOne({'Value':[12, 15, 16]}); { "acknowledged" : true, "insertedId" : ObjectId("5e0383edf5e889d7a51994dd") } > db.calculateAverage.insertOne({'Value':[30, 35, 40]}); { ... Read More

AmitDiwan
181 Views
To promote subfields to top level in projection, use $objectToArray and $arrayToObject. Let us first create a collection with documents:> db.promoteSubfieldsDemo.insertOne({'s':10, 'y':{'t':20, 'u':30, }}); { "acknowledged" : true, "insertedId" : ObjectId("5e038004190a577c668b55d5") }Following is the query to display all documents from a collection with the help of find() method ... Read More

AmitDiwan
690 Views
To delete specific record, use “$pull” and since we are updating the already created collection, use UPDATE().Let us create a collection with documents −> db.demo213.insertOne({ ... "id": 101, ... "details1": [ ... { ... "Name": "Chris", ... "details2": ... Read More

AmitDiwan
171 Views
To find a MongoDB document through a word, use find() and set the word like −word/iLet us create a collection with documents −> db.demo212.insertOne({"details":[{"Name":"John Doe"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e3e2c7603d395bdc21346ff") } > db.demo212.insertOne({"details":[{"Name":"Chris Brown"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e3e2c8003d395bdc2134700") } > db.demo212.insertOne({"details":[{"Name":"Robert ... Read More

AmitDiwan
88 Views
To test the values, use $type. Let us create a collection with documents −> db.demo211.insertOne({id:101, "Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3e298203d395bdc21346fa") } > db.demo211.insertOne({id:102, "Name":null}); { "acknowledged" : true, "insertedId" : ObjectId("5e3e2a5403d395bdc21346fb") }Display all documents from a collection with the help of find() method ... Read More

AmitDiwan
407 Views
To get the count of a specific value in MongoDB, use aggregate(). Let us create a collection with documents −> db.demo210.insertOne( ... { ... details: [ ... { ... ClientName: "Robert" ... }, ... ... Read More

AmitDiwan
291 Views
To convert filed value to create datetime day of month, use MongoDB aggregate(). Let us create a collection with documents −> db.demo209.insertOne( ... { ... "_id" : "101", ... "details" : [ ... { ... "dat" ... Read More

AmitDiwan
621 Views
To convert numeric string to number, use parseInt() in MongoDB. Let us create a collection with documents −> db.demo208.insertOne( { "value":"50"} ); { "acknowledged" : true, "insertedId" : ObjectId("5e3d92d803d395bdc21346f6") } > db.demo208.insertOne( { "value":"2350"} ); { "acknowledged" : true, "insertedId" : ObjectId("5e3d92dd03d395bdc21346f7") }Display all documents from ... Read More