Skip to main content
MongoDB

MongoDB - Insert one document

MongoDB - Insert one document

Inserts a single document into a MongoDB collection. Returns the unique identifier (_id) of the inserted document.


Options

Collection

Reference to the MongoDB: Select collection action the document will be inserted into.

Document

Document to insert, in MongoDB JSON format, for example { "nome": "João", "email": "joao@empresa.com", "status": "ativo" }.

Transaction (optional)

Reference to a MongoDB: Start transaction action when the operation must run inside a transaction. Optional field, available under the advanced options.

Returns

Javascript code

js
actions["action-id"].insertedId // unique identifier of the inserted document (Any)

Field selection

  • insertedId — unique identifier (_id) of the document inserted into the collection (Any)

Rules and Conditions

  • The Collection and Document fields are required.
  • The document must be a valid JSON object.
  • If the document has no _id field, MongoDB generates one automatically.