Quiz Entry - updated: 2026.07.05
How do you insert a document into a MongoDB collection?
Call insertOne() on the collection, passing the document as a plain JavaScript object.
await birthdays.insertOne({
name: "Anna",
day: new Date("1985-03-21")
});
- The object can contain nested objects and arrays
- MongoDB automatically adds an
_idfield if not provided - Returns a result object with
insertedId
Go deeper:
db.collection.insertOne() (MongoDB Manual) — full signature, the auto-generated
ObjectId, and the returnedinsertedId.