Lesson 20 of 22 · NoSQL

Inserting Documents

Insert JSON documents with insertOne and insertMany in a MongoDB-style database.

One document

db.collection.insertOne({ name: "Alice", age: 30 })

Several at once

db.collection.insertMany([{ name: "Bo" }, { name: "Cy" }])

Key Concepts

  • No fixed schema required
  • Each document gets a unique _id (returned as insertedId)
  • Fields can be any JSON type

Your challenge

Insert a user named Rosa Diaz with role "moderator", age 33 and isActive: true.

Solve it in your browser

Free, no sign-up. The NoSQL database runs in your browser; your answer is checked instantly, with hints if you need them.