
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
339 Views
Yes, it is possible using the UPDATE() method. Let us create a collection with documents −> db.demo27.insertOne({"StudentDetails":{"101":{"Subject":["Java"]}}}); { "acknowledged" : true, "insertedId" : ObjectId("5e15f9e822d07d3b95082e7f") } > db.demo27.insertOne({"StudentDetails":{"101":{"Subject":["MySQL"]}}}); { "acknowledged" : true, "insertedId" : ObjectId("5e15f9eb22d07d3b95082e80") }Display all documents from a collection with the help of find() method ... Read More

AmitDiwan
94 Views
For this, use positional operator($). To increment a field value by 1, use $inc operator. Let us create a collection with documents −>db.demo39.insertOne({"ProductDetails":[{"ProductName":"Product-1", "ProductPrice":349}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e176d54cfb11e5c34d898df") } >db.demo39.insertOne({"ProductDetails":[{"ProductName":"Product-2", "ProductPrice":998}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e176d61cfb11e5c34d898e0") } >db.demo39.insertOne({"ProductDetails":[{"ProductName":"Product-3", "ProductPrice":145}]}); { ... Read More

AmitDiwan
101 Views
To retrieve array values from a find query, use dot notation. Let us create a collection with documents −> db.demo38.insertOne({"ClientDetails":[{"ClientId":101, "ClientName":"Chris"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e176abccfb11e5c34d898d9") } > db.demo38.insertOne({"ClientDetails":[{"ClientId":102, "ClientName":"David"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e176ac7cfb11e5c34d898da") } > db.demo38.insertOne({"ClientDetails":[{"ClientId":103, "ClientName":"Mike"}]}); { "acknowledged" ... Read More

AmitDiwan
2K+ Views
To convert string to int, use parseInt() in MongoDB. Let us first create a collection with documents −> db.demo369.insertOne({"Price":"1000000"}); { "acknowledged" : true, "insertedId" : ObjectId("5e57e2e32ae06a1609a00aed") } > db.demo369.insertOne({"Price":"1747864"}); { "acknowledged" : true, "insertedId" : ObjectId("5e57e2e92ae06a1609a00aee") } > db.demo369.insertOne({"Price":"19548575"}); { "acknowledged" : true, "insertedId" ... Read More

AmitDiwan
1K+ Views
To select a specific subdocument in MongoDB, use find(). Let us create a collection with documents −> db.demo37.insertOne({"Details":[{"Name":"Chris", "Age":21}, {"Name":"David", "Age":23}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e176635cfb11e5c34d898d7") } > db.demo37.insertOne({"Details":[{"Name":"Sam", "Age":23}, {"Name":"Robert", "Age":25}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e17664acfb11e5c34d898d8") }Display all documents from a ... Read More

AmitDiwan
217 Views
At first, let us create a collection with letters and numbers, for example −7664734-541d-r5i5f-845575e-ghfhjrjr3747_demo368Access the above collection using db.getCollection(). Let us now create a collection with the name mentioned above −> db.createCollection('7664734-541d-r5i5f-845575e-ghfhjrjr3747_demo368'); { "ok" : 1 } >db.getCollection('7664734-541d-r5i5f-845575e-ghfhjrjr3747_demo368').insertOne({"FirstName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e57e2152ae06a1609a00aea") } >db.getCollection('7664734-541d-r5i5f-845575e-ghfhjrjr3747_demo368').insertOne({"FirstName":"David"}); { ... Read More

AmitDiwan
1K+ Views
To find on the basis of true or false values, use $exists in find(). You would also need dot notation for the same task.Let us first create a collection with documents −> db.demo367.insertOne( ... { "Id" : "102", ... "details" : [ { "Name" : "David"}, ... ... Read More

AmitDiwan
343 Views
To get distinct values, use MongoDB DISTINCT. For length, use LENGTH(). Let us create a collection with documents −> db.demo36.insertOne({"Names":["Chris", "Bob"]}); { "acknowledged" : true, "insertedId" : ObjectId("5e17643bcfb11e5c34d898d4") } > db.demo36.insertOne({"Names":["Mike", "Sam", "Carol"]}); { "acknowledged" : true, "insertedId" : ObjectId("5e176449cfb11e5c34d898d5") } > db.demo36.insertOne({"Names":["Chris", "Bob", "David"]}); { ... Read More

AmitDiwan
1K+ Views
To ignore NULL and UNDEFINED values, use $ne in MongoDB. Let us create a collection with documents −> db.demo35.insertOne({"Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e175e42cfb11e5c34d898d0") } > db.demo35.insertOne({"Name":null}); { "acknowledged" : true, 9 "insertedId" : ObjectId("5e175e46cfb11e5c34d898d1") } > db.demo35.insertOne({"Name":"Bob"}); { "acknowledged" : true, ... Read More

AmitDiwan
614 Views
To compare attributes, use $let along with $indexOfArray. Let us first create a collection with documents −> db.demo366.insertOne( ... { ... ... "Name" : "Chris", ... "details" : [ ... { ... "Id" : "John1", ... ... Read More