Overview
This node enables interaction with a MongoDB database, specifically supporting operations such as inserting documents into a specified collection. The "Insert" operation allows users to add one or multiple new documents to a MongoDB collection by specifying the fields and their values.
Common scenarios where this node is beneficial include:
- Adding new records to a MongoDB database from data collected in workflows.
- Automating data ingestion pipelines where new entries need to be stored in MongoDB.
- Integrating MongoDB with other services by programmatically inserting data.
For example, you could use this node to insert user registration data collected from a web form directly into a MongoDB collection named "users".
Properties
| Name | Meaning |
|---|---|
| Collection | The name of the MongoDB collection where the new document(s) will be inserted. |
| Fields | Comma-separated list of the fields to include in the new document(s). These define which properties are set on each inserted document. |
| Options | Additional options for insertion: - Date Fields: Comma-separated list of fields to parse as MongoDB Date type. - Use Dot Notation: Whether to use dot notation to access date fields. - OID Fields: Comma-separated list of fields to parse as MongoDB ObjectId type. |
Output
The output is an array of JSON objects representing the inserted documents. Each object includes the fields provided in the input along with an additional id field containing the MongoDB-generated identifier for the inserted document.
Example output structure for inserted documents:
[
{
"field1": "value1",
"field2": "value2",
"id": "ObjectId('...')"
},
...
]
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 an API key credential or similar authentication token.
- The node depends on the MongoDB driver and BSON utilities bundled within the node's code.
- Proper configuration of the MongoDB credentials in n8n is necessary, including database name and connection string or parameters.
Troubleshooting
Common Issues:
- Incorrect collection name or database name can cause failures.
- Malformed field names or unsupported data types may lead to insertion errors.
- If date or ObjectId fields are not correctly specified in options, the node might fail to parse them properly.
- Network connectivity issues to the MongoDB server.
Error Messages:
- Errors related to invalid database or collection names usually indicate misconfiguration.
- Parsing errors for date or ObjectId fields suggest incorrect formatting or missing option settings.
- Authentication errors imply invalid or missing credentials.
Resolutions:
- Verify that the collection and database names exist and are spelled correctly.
- Ensure that date and ObjectId fields are listed correctly in the options if used.
- Check network connectivity and firewall rules.
- Confirm that the API key or authentication token is valid and has sufficient permissions.