
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
151 Views
For such match and count, use $match in MongoDB. Let us create a collection with documents −> db.demo726.insertOne( ... { ... id:101, ... "details": [ ... { ... Name:"Chris" ... ... ... Read More

AmitDiwan
1K+ Views
To set filtering conditions, use $filter and $cond in MongoDB aggregate(). The $filter selects a subset of an array to return based on the specified condition. Let us create a collection with documents −> db.demo725.insertOne( ... { ... ... "details": { ... ... ... Read More

AmitDiwan
199 Views
You need to use custom logic with the help of while loop along with find() cursor. Let us create a collection with documents −> db.demo724.insertOne( ... { ... details: ... { ... id:101, ... otherDetails:[ ... Read More

AmitDiwan
772 Views
To count array elements from a specific field, use $size in MongoDB. Let us create a collection with documents −> db.demo723.insertOne({"Subject":["MySQL", "MongoDB"]}); { "acknowledged" : true, "insertedId" : ObjectId("5eab094d43417811278f588a") } > db.demo723.insertOne({"Subject":["C"]}); { "acknowledged" : true, "insertedId" : ObjectId("5eab095243417811278f588b") } > db.demo723.insertOne({"Subject":["C++", "Java", "Python"]}); { ... Read More

AmitDiwan
3K+ Views
To ignore null values in MongoDB, use "$ne" : null in aggregate(). Let us create a collection with documents −> db.demo722.insertOne( ... { ... id:101, ... details: [ ... { Name:""}, ... { Name: "David"}, ... Read More

AmitDiwan
813 Views
To count by multiple fields, use $facet in MongoDB. The $facet processes multiple aggregation pipelines within a single stage on the same set of input documents. Let us create a collection with documents −> db.demo721.insertOne( ... { ... ... "details1": { ... ... Read More

AmitDiwan
262 Views
To update all the values, use update() along with multi:true. Let us create a collection with documents −> db.demo720.insertOne({"SubjectName":"MySQL"}); { "acknowledged" : true, "insertedId" : ObjectId("5eaae7ca43417811278f5883") } > db.demo720.insertOne({"SubjectName":"Java"}); { "acknowledged" : true, "insertedId" : ObjectId("5eaae7ce43417811278f5884") } > db.demo720.insertOne({"SubjectName":"C"}); { "acknowledged" : true, "insertedId" ... Read More
MongoDB query to add a new field and concatenate the price result divided by a specific number in it

AmitDiwan
425 Views
To add a new field, use the $addFields in MongoDB. Let us create a collection with documents −> db.demo719.insertOne( ... { ... "Number":"7374644", ... "details" : { ... "otherDetails" : [ ... { ... Read More

AmitDiwan
391 Views
To display only unique records, use distinct() in MongoDB. Let us create a collection with documents −> db.demo613.insertOne({"Name":"Chris"});{ "acknowledged" : true, "insertedId" : ObjectId("5e988bd4f6b89257f5584d88") } > db.demo613.insertOne({"Name":"Bob"});{ "acknowledged" : true, "insertedId" : ObjectId("5e988bdbf6b89257f5584d89") } > db.demo613.insertOne({"Name":"Bob"});{ "acknowledged" : true, "insertedId" : ObjectId("5e988bddf6b89257f5584d8a") } > db.demo613.insertOne({"Name":"David"});{ "acknowledged" ... Read More

AmitDiwan
270 Views
Check for a specific field using MongoDB $exists. If that field does not exist in a document, then you need to display the same document with find().Let us create a collection with documents −> db.demo612.insertOne({id:1, "Info":[{Name:"Chris", Age:21}, {Name:"David"}]});{ "acknowledged" : true, "insertedId" : ObjectId("5e987372f6b89257f5584d87") }Display all documents from a ... Read More