
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
745 Views
Projection means only selected field must be visible. Set the field to 1, if you want to make it visible.Let us first create a collection with documents −> db.demo384.insertOne({"StudentName":"Chris Brown", "StudentCountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5e5b67a022064be7ab44e7f2") } > db.demo384.insertOne({"StudentName":"David Miller", "StudentCountryName":"AUS"}); { "acknowledged" : true, ... Read More

AmitDiwan
172 Views
To filter the logs containing the word “work” , use aggregate() along with $filter. Let us first create a collection with documents −> db.demo383.insertOne( ... { ... "ServerName":"Jboss", ... "ServerLogs": [ ... { ... ... Read More

AmitDiwan
446 Views
For this, use $project and in that, $size to get the length. Let us first create a collection with documents −> db.demo382.insertOne( ... { ... ... "Name" : "David", ... "details" : [ ... { ... ... Read More

AmitDiwan
629 Views
For this, use $indexOfArray. Let us first create a collection with documents −> db.demo381.insertOne({"Values":[10, 40, 60, 30, 60]}); { "acknowledged" : true, "insertedId" : ObjectId("5e5b59f72ae06a1609a00b15") } > db.demo381.insertOne({"Values":[100, 500, 700, 500, 800]}); { "acknowledged" : true, "insertedId" : ObjectId("5e5b59f72ae06a1609a00b16") } > db.demo381.insertOne({"Values":[20, 40, 30, 10, 60]}); ... Read More

AmitDiwan
1K+ Views
The $addToSet operator adds a value to an array unless the value is already present, in which case $addToSet does nothing to that array.Let us first create a collection with documents −> db.demo380.insertOne({ ... ... "details" : [ ... { ... "Name" ... Read More

AmitDiwan
1K+ Views
For projection on specific nested properties, use aggregate() in MongoDB. Let us first create a collection with documents −> db.demo379.insertOne( ... { ... "details1" : { ... "details2" : { ... "details3" : { ... ... Read More

AmitDiwan
180 Views
To manipulate subdocuments, use dot(.) notation in MongoDB. Let us first create a collection with documents −> db.demo378.insertOne( ... { ... Name: 'Chris', ... details:[ ... {id:101, Score:56}, ... {id:102, Score:78} ... ... Read More

AmitDiwan
430 Views
To concatenate, use $concat in MongoDB aggregate(). Let us first create a collection with documents −> db.demo377.insertOne({"ListOfIds":[1001, 1002, 1003, 1004, 1005, 1006, 1007]}); { "acknowledged" : true, "insertedId" : ObjectId("5e5a73462ae06a1609a00b0e") }Display all documents from a collection with the help of find() method −> db.demo377.find().pretty();This will produce the following ... Read More

AmitDiwan
647 Views
To update documents, you cannot use aggregation pipeline. You can use update(). Let us first create a collection with documents −> db.demo376.insertOne( ... { ... ... "id" :101, ... ... "details" : [ ... { ... ... Read More

AmitDiwan
565 Views
JavaScript function can be saved for reuse using a system collection called system.js. To store a function, use the db.collection.save(), Let us first create a function. Following is the query −> db.system.js.save({ ... _id: "displayMessage", ... value: function (data) { ... return 'The Name is: ... Read More