insert() - Insert a JSON document command

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

Syntax diagram

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

Command parameters

document
This parameter specifies the JSON document to insert.

Example

Insert a JSON document into a collection:
db.books.insert({
          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
         })
Sample output is as follows:
OK