Actions11
Overview
The node enables finding and replacing documents within a MongoDB collection. Specifically, the "Find And Replace" operation allows users to locate documents based on a key property and replace them entirely with new data. This is useful when you want to update whole documents atomically, for example, replacing a user profile document with updated information or swapping out configuration documents in bulk.
Common scenarios include:
- Replacing outdated records with fresh data identified by a unique key.
- Performing upserts where documents are inserted if they do not exist.
- Handling date fields correctly by parsing them into MongoDB Date types.
- Using dot notation to access nested fields during replacement.
Practical example: You have a collection of product documents identified by a SKU code. When product details change, you can use this operation to find each product by its SKU and replace the entire document with the updated product information, optionally inserting new products if they don't already exist.
Properties
| Name | Meaning |
|---|---|
| Collection | The name of the MongoDB collection where documents will be replaced. |
| Update Key | The property name used to identify which documents to replace (e.g., "id" or "_id"). |
| Fields | Comma-separated list of fields to include in the new document that will replace the existing one. |
| Upsert | Boolean flag indicating whether to insert the document if no matching document is found (true/false). |
| Options | Additional options for the operation: |
| - Date Fields | Comma-separated list of fields that should be parsed as MongoDB Date type before replacement. |
| - Use Dot Notation | Whether to interpret field names using dot notation to access nested properties (true/false). |
Output
The output consists of an array of JSON objects representing the documents after the find-and-replace operation. Each item corresponds to an input item processed, paired accordingly.
- For each replaced document, the output contains the full document data as JSON.
- If errors occur during processing individual items and "continue on fail" is enabled, the output includes an error message in place of the document.
- No binary data is produced by this operation.
Dependencies
- Requires a MongoDB database connection configured via credentials containing the connection string and database name.
- Uses the official MongoDB Node.js driver to perform operations.
- The node expects valid MongoDB collections and appropriate permissions to perform find-and-replace operations.
- No additional external services are required beyond MongoDB.
Troubleshooting
Common issues:
- Invalid or missing collection name: Ensure the collection exists in the target database.
- Incorrect update key: The update key must match a unique identifier in the documents; otherwise, replacements may not work as expected.
- Malformed field lists: The "Fields" and "Date Fields" inputs must be properly comma-separated without extra spaces.
- Date parsing errors: If date fields are incorrectly specified or contain invalid date strings, the operation may fail.
- Permissions: The connected MongoDB user must have write permissions on the target collection.
Error messages:
"Database \"<name>\" does not exist": The specified database was not found; verify the database name in credentials.- MongoDB driver errors related to ObjectId conversion: Ensure that the update key and IDs are correctly formatted.
- JSON parse errors on query or index definitions: Check that JSON inputs are valid and well-formed.
Resolutions:
- Double-check all input parameters for correctness.
- Validate that the MongoDB user has sufficient privileges.
- Use the "continue on fail" option to handle partial failures gracefully during batch operations.