Overview
This node enables interaction with a MongoDB database, specifically allowing users to update documents within a specified collection. The "Update" operation modifies existing documents based on a key property that identifies which records to update. It supports partial updates and can optionally insert new documents if no matching records are found (upsert).
Common scenarios include:
- Synchronizing data from other systems by updating existing MongoDB documents.
- Modifying specific fields of documents identified by a unique key such as an ID.
- Conditionally inserting new documents when no match is found, useful for ensuring data consistency.
For example, you might use this node to update user profiles in a MongoDB collection where the "userId" matches, changing their email or status fields, or insert a new profile if it does not exist.
Properties
Name | Meaning |
---|---|
Collection | The name of the MongoDB collection where documents will be updated. |
Update Key | The property name used to identify which documents to update (e.g., "id"). |
Fields | Comma-separated list of document fields to include in the update. |
Upsert | Boolean flag indicating whether to insert a new document if no existing document matches the update key. |
Options | Additional options for the update operation: |
- Date Fields | Comma-separated list of fields to parse as MongoDB Date type. |
- Use Dot Notation | Whether to use dot notation to access nested date fields. |
Output
The output is an array of JSON objects representing the documents after the update operation. Each object corresponds to an input item processed by the node, reflecting the updated state of the document.
If errors occur during processing individual items and the node is configured to continue on failure, the output for those items will contain an error
field with the error message.
No binary data is produced by this node.
Dependencies
- Requires a connection to a MongoDB database, authenticated via credentials containing necessary connection details (such as connection string or host, port, username, password).
- Uses the official MongoDB Node.js driver and BSON utilities for ObjectId handling.
- Requires proper configuration of the MongoDB credentials in n8n prior to execution.
Troubleshooting
Common issues:
- Incorrect collection name or database name leading to "collection not found" errors.
- Invalid update key property causing no documents to be matched or updated.
- Malformed JSON in fields or date fields causing parsing errors.
- Attempting to update documents with invalid ObjectId strings.
Error messages:
"Database \"<name>\" does not exist"
: Check that the database name in credentials is correct.- Errors related to ObjectId conversion: Ensure that the update key value is a valid ObjectId string if the key is
_id
. "The operation \"update\" is not supported!"
: This indicates an unsupported operation was selected; verify the operation parameter.
To resolve errors, verify all input parameters, ensure the MongoDB server is accessible, and confirm that the update key and fields are correctly specified.