
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
782 Views
For this, use aggregate() along with $group. Let us create a collection with documents −> db.demo627.insertOne({id:101, "Name":"Chris", "Marks":54}); { "acknowledged" : true, "insertedId" : ObjectId("5e9acb306c954c74be91e6b2") } > db.demo627.insertOne({id:102, "Name":"Bob", "Marks":74}); { "acknowledged" : true, "insertedId" : ObjectId("5e9acb3c6c954c74be91e6b3") } > db.demo627.insertOne({id:101, "Name":"Chris", "Marks":87}); { "acknowledged" : ... Read More

AmitDiwan
514 Views
For array interection in MongoDB, use the $setIntersection in aggregate(). Let us create a collection with documents −> db.demo625.insertOne( ... { ... Name: "John", ... Marks: [56, 98, 60] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e9ab8e16c954c74be91e6aa") ... Read More

AmitDiwan
85 Views
Yes, you can use ensureIndex(). MongoDB provides complete support for indexes on any field in a collection of documents.Let us create a collection with documents −> db.demo622.ensureIndex({_id:1, Name:1, Age:1}); { "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } > db.demo622.insertOne({_id:101, Name:"Chris", ... Read More

AmitDiwan
110 Views
To aggregate second element from input element, use mapReduce(). Map-reduce is a data processing paradigm for condensing large volumes of data into useful aggregated results. Let us create a collection with documents −> db.demo621.insert({ _id: 101, Name1: "John", Name2: "John" }); WriteResult({ "nInserted" : 1 }) > db.demo621.insert({ _id: 102, ... Read More

AmitDiwan
940 Views
Aggregation operations group values from multiple documents together, and can perform a variety of operations on the grouped data to return a single result.To aggregate in MongoDB, use aggregate(). Let us create a collection with documents −> db.demo620.insertOne({"Country":"IND", "City":"Delhi", state:"Delhi"}); { "acknowledged" : true, "insertedId" : ObjectId("5e9a8de96c954c74be91e6a1") } ... Read More

AmitDiwan
162 Views
Yes, we can do that using the NumberLong() datatype in MongoDB. Let us create a collection with documents −> db.demo618.insertOne({_id:NumberLong("6336366454"), Name:"Chris"}); { "acknowledged" : true, "insertedId" : NumberLong("6336366454") } > db.demo618.insertOne({_id:NumberLong("6336366455"), Name:"David"}); { "acknowledged" : true, "insertedId" : NumberLong("6336366455") } > db.demo618.insertOne({_id:NumberLong("6336366456"), Name:"Bob"}); { "acknowledged" : true, "insertedId" : NumberLong("6336366456") ... Read More

AmitDiwan
298 Views
For this, use dot notation along with $group in MongoDB. Let us create a collection with documents −> db.demo617.insertOne( ... { ... ... "clientDetails": { ... "Name": "Chris", ... "Age":32, ... "Project":"Online Library Management ... Read More

AmitDiwan
661 Views
In MongoDB aggregate(), use $group and aggregate collection. Let us create a collection with documents −> db.demo616.insertOne({"details":{"Name":"Chris", "Age":21}}); { "acknowledged" : true, "insertedId" : ObjectId("5e99bfac65492f6c60d00283") } > db.demo616.insertOne({"details":{"Name":"Chris", "Age":22}}); { "acknowledged" : true, "insertedId" : ObjectId("5e99bfb065492f6c60d00284") } > db.demo616.insertOne({"details":{"Name":"Bob", "Age":23}}); { "acknowledged" : true, ... Read More

AmitDiwan
125 Views
The $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.demo615.insert({"Value":100}); WriteResult({ "nInserted" : 1 }) > db.demo615.insert({"Value":"100"}); WriteResult({ "nInserted" : 1 }) > db.demo615.insert({"Value":"300"}); WriteResult({ "nInserted" : 1 }) > db.demo615.insert({"Value":300}); WriteResult({ "nInserted" ... Read More

AmitDiwan
1K+ Views
The ({$natural − 1}) works like LIFO(LAST IN FIRST OUT), that means last inserted document will be shown first.Let us create a collection with documents −> db.demo614.insertOne({"CountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5e988cddf6b89257f5584d8e") } > db.demo614.insertOne({"CountryName":"UK"}); { "acknowledged" : true, "insertedId" : ObjectId("5e988ce0f6b89257f5584d8f") } > ... Read More