Overview
This node enables interaction with a MongoDB database, specifically supporting operations to find and update documents within a specified collection. The "Find And Update" operation allows users to locate documents based on a key field and update them accordingly. It supports upserting (inserting if no matching document is found), selective field updates, and parsing of special MongoDB data types like ObjectId and Date.
Common scenarios where this node is beneficial include:
- Synchronizing data from external sources by updating existing records or inserting new ones.
- Maintaining user profiles or inventory items where updates are frequent and must be precise.
- Automating database maintenance tasks that require conditional updates.
Practical example: Suppose you have a collection of products identified by a unique SKU. You can use this node to update the price and description of products by specifying the SKU as the update key. If a product does not exist, it can optionally insert it (upsert).
Properties
| Name | Meaning |
|---|---|
| Collection | The name of the MongoDB collection to operate on. |
| Update Key | The property name used to identify which documents to update (e.g., "id" or "_id"). |
| Fields | Comma-separated list of fields to include in the updated document. |
| Upsert | Boolean flag indicating whether to insert a new document if no matching document is found. |
| Options | Additional options for the 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. |
| - OID Fields | Comma-separated list of fields to parse as MongoDB ObjectId type. |
Output
The output is an array of JSON objects representing the documents after the update operation:
- For successful updates, each item corresponds to an updated document including the fields specified.
- In case of errors during processing individual items (if "continue on fail" is enabled), the output includes an
errorfield describing the issue. - When inserting documents, the output includes the inserted documents with their generated IDs.
- No binary data is output by this node.
Dependencies
- Requires a MongoDB database connection configured via credentials containing the necessary authentication details.
- Uses MongoDB Node.js driver and BSON utilities internally.
- The node expects valid MongoDB connection parameters and permissions to perform read/write operations on the specified collection.
Troubleshooting
Common issues:
- Invalid or missing MongoDB credentials will cause connection failures.
- Incorrect collection names or database names will result in errors.
- Malformed queries or invalid JSON in query fields can cause parsing errors.
- Using an incorrect update key that does not exist in documents will prevent updates.
- Attempting to update
_idfields incorrectly may cause errors; the node converts string IDs to ObjectId when appropriate.
Error messages:
"Database \"<name>\" does not exist": Check that the database name is correct and accessible."The operation \"<operation>\" is not supported!": Ensure the selected operation is valid.- MongoDB driver errors related to query syntax or permissions should be reviewed and corrected.
Resolutions:
- Verify credentials and connection strings.
- Confirm collection and database names.
- Validate input JSON and field names.
- Enable "continue on fail" to handle partial failures gracefully.