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
Writing a MongoDB insert statement for multiple insert at a time
For multiple insert, use insert() in MongoDB. Let us create a collection with document −
> db.demo689.insert([
... {ClientName:"Chris","ClientAge":34,"ClientCountryName":"US"},
... {ClientName:"David","ClientAge":28,"ClientCountryName":"UK"},
... {ClientName:"Bob","ClientAge":39,"ClientCountryName":"AUS"},
... ]);
BulkWriteResult({
"writeErrors" : [ ],
"writeConcernErrors" : [ ],
"nInserted" : 3,
"nUpserted" : 0,
"nMatched" : 0,
"nModified" : 0,
"nRemoved" : 0,
"upserted" : [ ]
})
Display all documents from a collection with the help of find() method −
> db.demo689.find();
This will produce the following output −
{ "_id" : ObjectId("5ea580dfa7e81adc6a0b3967"), "ClientName" : "Chris", "ClientAge" : 34, "ClientCountryName" : "US" }
{ "_id" : ObjectId("5ea580dfa7e81adc6a0b3968"), "ClientName" : "David", "ClientAge" : 28, "ClientCountryName" : "UK" }
{ "_id" : ObjectId("5ea580dfa7e81adc6a0b3969"), "ClientName" : "Bob", "ClientAge" : 39, "ClientCountryName" : "AUS" }Advertisements