Insert documents into MongoDB collection you can use two methods in the MongoDB shell or in your application.
- insertOne()
- insertMany()
1. insertOne()-
You used insertOne() to insert a single document into a collection.
Example-
db.Collection_name.insertOne({ name: "Tutorials On Web", age: 20, email: "info@tutorialsonweb.com" })
Replace Collection_name By actual collection name
2. insertMany()-
You used insertMany() to insert a multiple document into a collection.
db.Collection_name.insertMany([
{ name: "Tutorials On Web", age: 25, email: "info@tutorialsonweb.com" },
{ name: "Tutorials On Web 1", age: 30, email: "hello@tutorialsonweb.com" }
])
Replace Collection_name By actual collection name