insertMany() - Insert multiple JSON documents command

Inserts multiple documents into a collection. If the collection does not exist, then it is created automatically.

Syntax diagram

Read syntax diagramSkip visual syntax diagramdb.collection. insertMany([document, document, document])

Command parameters

document
Specifies the JSON document to insert.

Examples

The following example shows the command syntax for inserting multiple documents into the collection, books:
db.books.insertMany([
         {
          isbn: "123-456-089", 
          author: "Robert, Jules", 
          title: "Journey to the Ocean", 
         },
         {
          isbn: "123-456-780", 
          author: "Verne, Hall", 
          title: "Journey to the Moon", 
         },
         {
          isbn: "123-456-709", 
          author: "James, Vale", 
          title: "Journey to the Forest", 
         },
         {
          isbn: "123-456-900", 
          author: "Martin, Hall", 
          title: "Journey for self", 
         }
])
The following example shows the successful output from running the insertMany command:
Command successfully completed.