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 8359 Articles
AmitDiwan
1K+ Views
Use $replaceRoot in MongoDB aggregation. The $replaceRoot replaces the input document with the specified document. The operation replaces all existing fields in the input document, including the _id field. Let us create a collection with documents −> db.demo733.insertOne( ... { ... "SubjectDetails": ... ... Read More
AmitDiwan
499 Views
You can use $set. Let us create a collection with documents −> db.demo732.insertOne({_id:1, Language:"English"}); { "acknowledged" : true, "insertedId" : 1 } > db.demo732.insertOne({_id:2, Language:"Hindi"}); { "acknowledged" : true, "insertedId" : 2 }Display all documents from a collection with the help of find() method −> db.demo732.find();This will produce the following ... Read More
AmitDiwan
914 Views
To display a specific field, use $project along with $unwind. To ignore a field, set to 0. Let us create a collection with documents −> db.demo731.insertOne({ "ProductInformation": [ { ProductId:"Product-1", ProductPrice:80 }, { ProductId:"Product-2", ProductPrice:45 }, { ProductId:"Product-3", ProductPrice:50 } ] } ); { "acknowledged" : true, "insertedId" ... Read More
AmitDiwan
531 Views
To match, use $match in MongoDB. For values greater than a specific number, use $gt. Let us create a collection with documents −> db.demo730.insertOne({"Name" : "Chris", "Marks" : 33 }); { "acknowledged" : true, "insertedId" : ObjectId("5eac54cd56e85a39df5f6339") } > db.demo730.insertOne({ "Name" : "David", "Marks" : 89}); { ... Read More
AmitDiwan
159 Views
For mass insertion, use the concept of insertMany() in MongoDB. The insertMany() inserts multiple documents into a collection.Let us create a collection with documents −> db.demo729.insertMany( [ ... { BankName:"HDFC Bank", cardType:"Credit", "CustomerName":[{Name:"Chris", Age:25}]}, ... { BankName:"ICICI Bank", cardType:"Debit", "CustomerName":[{Name:"Bob", Age:22}]}, ... { BankName:"Kotak Bank", cardType:"Debit", "CustomerName":[{Name:"David", ... Read More
AmitDiwan
409 Views
To check the records with Price less than a specific value, use $lt. Let us create a collection with documents −> db.demo728.insertOne({Price:75}); { "acknowledged" : true, "insertedId" : ObjectId("5eab413c43417811278f589b") } > db.demo728.insertOne({Price:59}); { "acknowledged" : true, "insertedId" : ObjectId("5eab414043417811278f589c") } > db.demo728.insertOne({Price:79}); { "acknowledged" : ... Read More
AmitDiwan
1K+ Views
Search for email string using MongoDB find(). Let us create a collection with documents −> db.demo727.insertOne({UserId:"John@email.com"}); { "acknowledged" : true, "insertedId" : ObjectId("5eab375f43417811278f5898") } > db.demo727.insertOne({UserId:"John@yahoo.com"}); { "acknowledged" : true, "insertedId" : ObjectId("5eab376043417811278f5899") } > db.demo727.insertOne({UserId:"Chris@EMAIL.com"}); { "acknowledged" : true, "insertedId" : ObjectId("5eab376143417811278f589a") }Display ... Read More
AmitDiwan
183 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
226 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