MongoDB TutorialLesson 6Free preview
MongoDB Insert
This lesson is part of MongoDB · All levels
Summary
This lesson discusses the insertion of documents in mongosh using insertOne() for one document and insertMany() for many documents at once. MongoDB automatically creates field IDs if you don't specify it yourself, and the same ID cannot be used twice. The return of the insert is acknowledged with the insertedId of the first document.
Key points
- InsertOne() inserting a single document; insertMany() receiving an array of documents
- _id is automatically created when not provided and must be unique
- InsertMany() adds documents in order to array
- Results of the insert load acknowledged and insertedId
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.