Overview
This node allows you to insert documents into a MongoDB collection. It is useful when you want to add new records to your MongoDB database directly from an n8n workflow. Typical use cases include adding user data, logging events, or storing any structured information dynamically generated or collected during the workflow execution.
For example, you might use this node to insert new customer records into a "customers" collection after collecting their details via a form, or to log transaction details into a "transactions" collection for later analysis.
Properties
| Name | Meaning |
|---|---|
| Collection | The name of the MongoDB collection where the new document(s) will be inserted. |
| Fields | Comma-separated list of fields to include in the new document(s). These specify which input data fields to map into the MongoDB document. |
| Options | Additional options for insertion: - Date Fields: Comma-separated list of fields to parse as Mongo Date type. - Use Dot Notation: Whether to use dot notation to access date fields. - _id as ObjectId: Automatically convert the _id field to MongoDB ObjectId type; if false, _id remains a string. |
Output
The output JSON array contains the inserted documents with their fields as specified in the input, plus an additional id property representing the MongoDB-generated identifier for each inserted document.
- Each item corresponds to one inserted document.
- The
idfield holds the unique identifier assigned by MongoDB upon insertion. - No binary data is output by this node.
Example output item:
{
"name": "John Doe",
"email": "john@example.com",
"id": "60d5ec49f1a4c12d4c8b4567"
}
Dependencies
- Requires a MongoDB instance accessible via connection string or parameters.
- Needs an API key credential or equivalent authentication configured in n8n to connect securely to MongoDB.
- Uses the official MongoDB Node.js driver internally.
Troubleshooting
- Connection errors: Ensure the MongoDB connection string and credentials are correct and that the database server is reachable.
- Invalid collection name: Verify the collection name exists or is correctly spelled.
- Field parsing issues: If date fields are not parsed correctly, check the format of the input data and the "Date Fields" option.
- _id conversion errors: If
_idvalues are invalid ObjectId strings but the option to convert them is enabled, insertion may fail. Disable automatic conversion or ensure valid ObjectId strings. - Partial insertions: If multiple documents are inserted and some fail, enabling "Continue On Fail" allows the node to proceed with others; otherwise, it throws an error.