Overview
The node performs various MongoDB operations on specified collections within a database. It connects to a MongoDB instance and executes commands such as updating documents, finding documents, aggregating data, inserting new documents, replacing existing documents, or deleting documents.
For the Replace One operation specifically, the node replaces a single document in a MongoDB collection that matches a given query with a new document provided by the user. This is useful when you want to completely overwrite an existing document based on some criteria.
Common scenarios:
- Updating a user's profile information entirely by replacing the old document.
- Replacing configuration settings stored as documents in a collection.
- Overwriting outdated records with fresh data matching certain conditions.
Example:
You have a collection users
and want to replace the document where username
is "johndoe"
with a new document containing updated user details.
Properties
Name | Meaning |
---|---|
Collection | The name of the MongoDB collection where the operation will be performed. |
Query (JSON Format) | A JSON object specifying the filter criteria to find the document to replace. |
Document (JSON Format) | The new document data that will replace the matched document in the collection. |
Output
The output is an array of JSON objects, each representing the replaced document as it was provided in the input (i.e., the new document). Each item corresponds to one input item processed.
Example output item:
{
"field": "value",
"anotherField": 123
}
No additional metadata about the operation result (such as acknowledgment or modified count) is returned in the output.
The node does not output binary data.
Dependencies
- Requires a connection to a MongoDB database.
- Needs credentials for authenticating with the MongoDB instance (e.g., connection string and database name).
- The node uses the official MongoDB Node.js driver internally to perform operations.
Troubleshooting
- Invalid JSON in Query or Document: Since the query and document inputs are parsed from JSON strings, invalid JSON syntax will cause errors. Ensure proper JSON formatting.
- No Matching Document Found: If the query does not match any document, the replace operation will not modify any document but still returns the new document in output. Verify your query criteria.
- Connection Issues: Errors connecting to MongoDB may occur if credentials or connection strings are incorrect. Double-check your MongoDB credentials and network accessibility.
- Permission Denied: The authenticated user must have write permissions on the target collection to perform replacements.
- Error Handling: If the node encounters an error and "Continue On Fail" is enabled, it outputs an error message in the JSON field instead of stopping execution.