Skip to content
Justice Tech School

Insert One Document

insertOne adds a single document and returns its _id. The collection is created automatically.

Example
db.students.insertOne({ name: "Ada", age: 30, city: "Lagos" })
// { acknowledged: true, insertedId: ObjectId("...") }

Exercise

Add one document.

db.students.({ name: "Ada" })

Quiz Test

What does insertOne return?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.