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 where this node is beneficial include:
- Automating data ingestion workflows where new records need to be added to a MongoDB database.
- Integrating form submissions or external data sources into MongoDB for storage.
- Batch inserting multiple documents prepared from previous workflow steps.
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 fields to include in the new document(s). Only these fields from input data are used. |
Options | Additional options for insertion: - Date Fields: Comma-separated list of fields parsed as Mongo Date type. - Use Dot Notation: Whether to use dot notation to access date fields (true/false). |
Output
The output is an array of JSON objects representing the inserted documents. Each object contains the fields that were inserted along with an additional id
field representing the unique identifier assigned by MongoDB to the inserted document.
Example output item:
{
"name": "John Doe",
"email": "[email protected]",
"id": "60d5ec49f8d2e30a3c4b0f1a"
}
If any error occurs during insertion and the node is configured to continue on failure, the output will contain an object with an error
property describing the issue.
Dependencies
- Requires a MongoDB instance accessible via connection string or parameters.
- Needs credentials providing access to the MongoDB database.
- Uses BSON and MongoDB Node.js driver libraries internally.
- No additional environment variables beyond standard MongoDB credentials are required.
Troubleshooting
Common issues:
- Incorrect collection name or database name causing "collection does not exist" errors.
- Malformed or missing fields in input data leading to insertion failures.
- Invalid date formats in fields expected to be parsed as dates.
- Network or authentication errors connecting to MongoDB.
Error messages:
"Database \"<name>\" does not exist"
: Verify the database name in credentials.- Errors related to invalid ObjectId format if
_id
fields are incorrectly formatted. - General insertion errors may indicate schema violations or connectivity problems.
To resolve errors:
- Double-check collection and database names.
- Ensure input data matches expected field formats.
- Confirm network connectivity and credential validity.
- Use the "continue on fail" option to handle partial failures gracefully.