
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
MongoDB bulk insert for documents
For bulk insert, you can use insert() in MongoDB. Let us create a collection with documents −
> var manyDocument = db.demo255.initializeUnorderedBulkOp(); > manyDocument.insert( { "Name":"Chris",Age:24} ); > manyDocument.insert( {"Name":"Bob",Age:22 } ); > manyDocument.insert( { "Name":"David",Age:23 } ); > manyDocument.execute(); 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.demo255.find();
This will produce the following output −
{ "_id" : ObjectId("5e47a25e1627c0c63e7dba82"), "Name" : "Chris", "Age" : 24 } { "_id" : ObjectId("5e47a25e1627c0c63e7dba83"), "Name" : "Bob", "Age" : 22 } { "_id" : ObjectId("5e47a25e1627c0c63e7dba84"), "Name" : "David", "Age" : 23 }
- Related Questions & Answers
- Perform Bulk insert in MongoDB?
- Check for existing documents/embedded documents in MongoDB
- Aggregation in MongoDB for nested documents?
- Search for multiple documents in MongoDB?
- How to validate documents before insert or update in MongoDB?
- Insert to specific index for MongoDB array?
- How to insert new documents into a MongoDB collection in your database?
- Writing a MongoDB insert statement for multiple insert at a time
- MongoDB - Query embedded documents?
- MongoDB query for documents matching array, irrespective of elements order
- MongoDB query for counting the distinct values across all documents?
- Best option for locking bulk user accounts in SAP
- Sum MongoDB Sub-documents field?
- MongoDB filter multiple sub-documents?
- MongoDB query to skip documents
Advertisements