insertOne() - Insert a single JSON document command

Inserts a single JSON document into a collection. If the collection does not exist, then it is created automatically.

Syntax diagram

Read syntax diagramSkip visual syntax diagramdb.collection. insertOne(document)

Command parameters

document
Specifies the JSON document to insert.

Examples

The following example shows the command syntax for inserting a document into the collection, books:
db.books.insertOne({
          isbn: "123-456-789", 
          author: "Verne, Jules", 
          title: "Journey to the Center of the Earth", 
          abstract: "Classic science fiction novel in an unusual setting", 
          price: 6.00, 
          pages: 276, 
          category: "Fantasy",
          sales: 500.50
         })
The following example shows the successful output from running the insertOne command:
Command successfully completed.