LOGBOOK

HELP

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 _id field if not provided
  • Returns a result object with insertedId

Go deeper:

From Quiz: WEBT / Database Connections | Updated: Jul 05, 2026