Overview
This node allows you to interact with a MongoDB database by performing various operations such as inserting, updating, deleting, finding, and aggregating documents within specified collections. The "Insert" operation specifically enables adding new documents into a chosen MongoDB collection.
Common scenarios for this node include:
- Adding new records to a MongoDB collection from data processed in an n8n workflow.
- Automating data ingestion pipelines where new entries need to be stored in MongoDB.
- Integrating MongoDB with other services by programmatically inserting documents based on external triggers or inputs.
For example, you could use this node to insert user registration data collected from a web form directly into a MongoDB users collection.
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). |
| Options | Additional options for insertion: |
| Date Fields | Comma-separated list of fields that should be parsed as MongoDB Date type. |
| Use Dot Notation | Boolean flag indicating whether to use dot notation to access date fields. |
| OID Fields | Comma-separated list of fields that should be parsed as MongoDB ObjectId type. |
Output
The output is a JSON array where each element corresponds to one inserted document. Each object contains the original fields plus an id field representing the MongoDB-generated identifier for the inserted document.
Example output item:
{
"name": "John Doe",
"description": "Sample user",
"id": "60d5ec49f1a4c12d4c8b4567"
}
If the node encounters errors during insertion and is configured to continue on failure, the output will contain objects with an error property describing the issue.
Dependencies
- Requires a connection to a MongoDB database, authenticated via credentials containing either a connection string or parameters to build one.
- Uses the official MongoDB Node.js driver and BSON utilities for handling special types like ObjectId and Date.
- Requires proper configuration of the MongoDB credentials in n8n, including database name and authentication details.
Troubleshooting
- Common issues:
- Invalid or missing MongoDB credentials can cause connection failures.
- Incorrect collection names or fields may result in insertion errors.
- Improperly formatted date or ObjectId fields can cause parsing errors.
- Error messages:
"Database \"<name>\" does not exist"indicates the specified database was not found; verify the database name.- Errors related to invalid ObjectId or date formats suggest checking the
OID FieldsandDate Fieldsoptions. - If the node throws
"The operation \"insert\" is not supported!", ensure the operation parameter is correctly set to "insert".
- To resolve errors, verify all input parameters, ensure the MongoDB server is accessible, and confirm that the data matches expected formats.