- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6702 Articles for Database
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
76 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", Age:23}]} ... ] ); { "acknowledged" : true, "insertedIds" : [ ObjectId("5eac510d56e85a39df5f6333"), ObjectId("5eac510d56e85a39df5f6334"), ObjectId("5eac510d56e85a39df5f6335") ] }Display all documents from a collection with the help of find() method −> db.demo729.find().pretty();This will produce the following output −{ "_id" : ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
321 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" : true, "insertedId" : ObjectId("5eab414543417811278f589d") } > db.demo728.insertOne({Price:89}); { "acknowledged" : true, "insertedId" : ObjectId("5eab414843417811278f589e") }Display all documents from a collection with the help of find() method −> db.demo728.find();This will produce the following output −{ "_id" : ObjectId("5eab413c43417811278f589b"), "Price" : 75 } { "_id" : ObjectId("5eab414043417811278f589c"), "Price" : ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
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 all documents from a collection with the help of find() method −> db.demo727.find();This will produce the following output −{ "_id" : ObjectId("5eab375f43417811278f5898"), "UserId" : "John@email.com" } { "_id" : ObjectId("5eab376043417811278f5899"), "UserId" : "John@yahoo.com" } { "_id" : ObjectId("5eab376143417811278f589a"), "UserId" : "Chris@EMAIL.com" }Following is the query to search for @email like ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
108 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" ... ... }, ... { ... Name:"Chris" ... ... }, ... { ... Name:"Bob" ... } ... ] ... ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
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": { ... ... "userMessages": [ ... { ... "Messages": [ ... { "Message": "Hello" }, ... { "Message": "How" }, ... ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
146 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:[ ... {Name:"Chris"} ... ] ... } ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5eab0cce43417811278f5890") } > > > db.demo724.insertOne( ... { ... ... } ... ); { "acknowledged" : true, ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
652 Views
To count array elements from a specific field, use $size in MongoDB. Let us create a collection with documents −> db.demo723.insertOne({"Subject":["MySQL", "MongoDB"]}); { "acknowledged" : true, "insertedId" : ObjectId("5eab094d43417811278f588a") } > db.demo723.insertOne({"Subject":["C"]}); { "acknowledged" : true, "insertedId" : ObjectId("5eab095243417811278f588b") } > db.demo723.insertOne({"Subject":["C++", "Java", "Python"]}); { "acknowledged" : true, "insertedId" : ObjectId("5eab095f43417811278f588c") }Display all documents from a collection with the help of find() method −> db.demo723.find();This will produce the following output −{ "_id" : ObjectId("5eab094d43417811278f588a"), "Subject" : [ "MySQL", "MongoDB" ] } { "_id" : ObjectId("5eab095243417811278f588b"), "Subject" : [ "C" ] } { "_id" : ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
To ignore null values in MongoDB, use "$ne" : null in aggregate(). Let us create a collection with documents −> db.demo722.insertOne( ... { ... id:101, ... details: [ ... { Name:""}, ... { Name: "David"}, ... {Name:null}, ... {Name:"Carol"} ... ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5eab07d543417811278f5889") }Display all documents from a collection with the help of find() method −> db.demo722.find();This will produce the following output ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
704 Views
To count by multiple fields, use $facet in MongoDB. The $facet processes multiple aggregation pipelines within a single stage on the same set of input documents. Let us create a collection with documents −> db.demo721.insertOne( ... { ... ... "details1": { ... "id":101 ... ... }, ... "details2": { ... "id":101 ... }, ... "details3": { ... "id":101 ... } ... } ... ); { "acknowledged" : ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
214 Views
To update all the values, use update() along with multi:true. Let us create a collection with documents −> db.demo720.insertOne({"SubjectName":"MySQL"}); { "acknowledged" : true, "insertedId" : ObjectId("5eaae7ca43417811278f5883") } > db.demo720.insertOne({"SubjectName":"Java"}); { "acknowledged" : true, "insertedId" : ObjectId("5eaae7ce43417811278f5884") } > db.demo720.insertOne({"SubjectName":"C"}); { "acknowledged" : true, "insertedId" : ObjectId("5eaae7d143417811278f5885") } > db.demo720.insertOne({"SubjectName":"C++"}); { "acknowledged" : true, "insertedId" : ObjectId("5eaae7d543417811278f5886") }Display all documents from a collection with the help of find() method −> db.demo720.find();This will produce the following output −{ "_id" : ObjectId("5eaae7ca43417811278f5883"), "SubjectName" : "MySQL" } { "_id" : ObjectId("5eaae7ce43417811278f5884"), "SubjectName" : "Java" } { ... Read More