
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
124 Views
For this, check using $where in MongoDB. Let us create a collection with documents −> db.demo292.insertOne({FirstName:"Chris", LastName:"Brown", ... "Friend":{FirstName:"David", "LastName":"Miller"} ... } ...); { "acknowledged" : true, "insertedId" : ObjectId("5e4c10aa5d93261e4bc9ea30") } > db.demo292.insertOne({FirstName:"John", LastName:"Doe", ... "Friend":{FirstName:"Mike", "LastName":"Doe"} ...} ...); { "acknowledged" : true, ... Read More

AmitDiwan
591 Views
To get the sum of two columns, use $add. Let us create a collection with documents −> db.demo291.insertOne({"Value1":10, "Value2":50}); { "acknowledged" : true, "insertedId" : ObjectId("5e4c0e1e5d93261e4bc9ea2f") }Display all documents from a collection with the help of find() method −> db.demo291.find();This will produce the following output −{ "_id" : ... Read More

AmitDiwan
845 Views
For exact match, you can use $exists that checks for a match. Let us create a collection with documents −> db.demo290.insertOne({"ListOfName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e4c0c9e5d93261e4bc9ea2d") } > db.demo290.insertOne({"ListOfName":["Chris", "David"]}); { "acknowledged" : true, "insertedId" : ObjectId("5e4c0cb05d93261e4bc9ea2e") }Display all documents from a collection with ... Read More

AmitDiwan
257 Views
To make an array of multiple arrays, use $unwind in MongoDB aggregate. Let us create a collection with documents −> db.demo289.insertOne({"Section":["A", "B", "E"], "Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e4c06fcf49383b52759cbc3") } > db.demo289.insertOne({"Section":["C", "D", "B"], "Name":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e4c070af49383b52759cbc4") }Display all ... Read More

AmitDiwan
277 Views
Let us create a collection with documents −>db.demo288.insertOne({"Name":"Chris", details:[{"CountryName":"US", Marks:78}, {"CountryName":"UK", Marks:68}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e4c0393f49383b52759cbbe") }Display all documents from a collection with the help of find() method −> db.demo288.find();This will produce the following output −{ "_id" : ObjectId("5e4c0393f49383b52759cbbe"), "Name" : "Chris", "details" : [ ... Read More

AmitDiwan
4K+ Views
To get distinct values, use distinct() in MongoDB. It finds the distinct values for a specified field across a single collection or view and returns the results in an array.Let us create a collection with documents −> db.demo287.insertOne({"details":{"AllVowels":["a", "u", "u", "o", "e", "a", "o", "i"]}}); { "acknowledged" : true, ... Read More

AmitDiwan
1K+ Views
To get the min and max values, use $min and $max. Let us create a collection with documents −> db.demo286.insertOne({"details":[{Value1:70, Value2:50}, {Value1:30, Value2:36}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e4ac743f49383b52759cbbc") }Display all documents from a collection with the help of find() method −> db.demo286.find().pretty();This will produce the following ... Read More

AmitDiwan
93 Views
The command you can use is db.runCommand(). Let us first switch to admin −> use admin switched to db adminNow, run the command −> db.runCommand({listDatabases : 1})This will produce the following output −{ "databases" : [ { "name" : "admin", ... Read More

AmitDiwan
237 Views
For this, use aggregate() in MongoDB. Let us create a collection with documents −> db.demo285.insertOne( ... {... details : [ ... { ... Name : "Chris" ... }, ... { ... Name2: "Bob" ... ... Read More

AmitDiwan
507 Views
To export MongoDB has a command mongoexport. Following is the syntax −mongoexport -d yourDatabaseName -c yourCollectionName -f yourFieldName --type=csv -o yourFileLocation/FileName;Let us create a collection with documents −> db.demo284.insertOne({"FirstName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e4abc9e9127fafea82a2cfc") } > db.demo284.insertOne({"FirstName":"Robert"}); { "acknowledged" : true, "insertedId" : ObjectId("5e4abca39127fafea82a2cfd") ... Read More