Overview
This node performs advanced MongoDB operations with type control, specifically supporting insert, update, and find operations on MongoDB collections. For the 'update' operation, it updates an existing document in a specified collection based on a filter field and value, with options for upserting (inserting if not found) and using different MongoDB update operators like $set, $push, $addToSet, and $pull. It is useful for workflows that need to modify MongoDB documents dynamically based on incoming data, such as updating user profiles, inventory records, or log entries.
Use Case Examples
- Updating a user document in a MongoDB collection by filtering with the user's _id and setting new values for fields like email and name.
- Using the $push operator to add an item to an array field in a document, such as adding a new tag to a blog post's tags array.
- Performing an upsert operation to insert a new document if no existing document matches the filter criteria.
Properties
| Name | Meaning |
|---|---|
| Coleção | The name of the MongoDB collection where the update operation will be performed. |
| Filtro de Update | The field name used as a filter to find the document to update (e.g., _id, email). |
| Valor do Filtro | The path in the input item that contains the value used to filter the document to update (e.g., json.id). |
| Tipo do Filtro | The data type of the filter field, which can be String, ObjectId, or Number. |
| Upsert | Boolean flag indicating whether to insert the document if it does not exist (true to enable upsert). |
| Operador de Update | The MongoDB update operator to use for the update operation, such as $set to replace values or $push to add to an array. |
| Mapeamento de Campos | Field mappings with specific data types and source paths to map input data fields to MongoDB document fields. |
Output
JSON
success- Indicates if the update operation was successful.matchedCount- Number of documents matched by the filter.modifiedCount- Number of documents actually modified.upsertedId- The ID of the inserted document if an upsert occurred.filter- The filter object used to find the document.
Dependencies
- MongoDB Node.js Driver
Troubleshooting
- Common issues include invalid filter values, such as an incorrectly formatted ObjectId string or invalid data types for fields, which will throw validation errors.
- Errors related to connection issues with MongoDB, such as incorrect connection strings or authentication failures, can occur.
- If the update filter value path is incorrect or missing in the input data, the update will fail or not match any documents.
- To resolve errors, ensure that filter values conform to the expected types and that the MongoDB connection credentials are correct.
Links
- MongoDB Update Operators - Official MongoDB documentation on update operators like $set, $push, $addToSet, and $pull.
- MongoDB Node.js Driver - Official MongoDB Node.js driver documentation used by this node for database operations.
