Full-Stack Web Development with Vue.js and Node

(singke) #1
Introducing MongoDB Chapter 3

insert()

This command inserts single as well as multiple documents into a collection. It does the job
of both the insertOne() and the insertMany() commands. To insert a single document,


we can use:


> db.users.insert(
{ name: "Mike", email: "[email protected]" }
)

If the command is executed successfully, we should see the following output:


Now, if we want to insert multiple documents, we can simply use:


> db.users.insert(
[
{ name: "Josh", email: "[email protected]" },
{ name: "Ross", email: "[email protected]" },
]
)
Free download pdf