We will inject some data in the nuxt-app database with the MongoDB CRUD operations that you have learned about in the previous section.
Inserting documents
We can insert new documents by using the insertOne or insertMany methods as follows:
- Insert a single document: We can insert a new document like this:
> db.<collection>.insertOne(<document>)
Let's insert one document with the following code:
db.user.insertOne(
{
name: "Alexandre",
age: 30,
slug: "alexandre",
role: "admin",
status: "ok"
}
)
You should get a similar result to this:
{
"acknowledged" : true,
"insertedId" : ObjectId("5ca...")
}
- Insert multiple documents: We can insert multiple new documents like this:
> db.<collection>.insertMany([<document>,<document>,<document>,...])
Let's insert two documents with the following code:
> db.user.insertMany([
...