Mongo DB OID icon

Mongo DB OID

Find, insert and update documents in MongoDB

Overview

This node performs an update operation on documents within a specified MongoDB collection. It updates documents based on a key field (default is 'id') and can selectively update specified fields. It supports options like upsert (inserting if no matching document is found), parsing date fields, and handling MongoDB ObjectId fields. This node is useful for scenarios where you need to modify existing records in a MongoDB database, such as updating user profiles, product details, or any other document data based on a unique identifier.

Use Case Examples

  1. Updating user information in a MongoDB collection by specifying the user ID as the update key and providing new values for selected fields.
  2. Performing an upsert operation to insert a new document if no existing document matches the update key, ensuring data consistency.
  3. Updating documents with date fields and ObjectId fields correctly parsed and formatted for MongoDB.

Properties

Name Meaning
Collection The MongoDB collection where the update operation will be performed.
Update Key The property name used to identify which documents should be updated, typically '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 update operation, including date fields, use of dot notation, and ObjectId fields.

Output

JSON

  • deletedCount - Number of documents deleted (not applicable for update but part of other operations).
  • id - Identifier of the inserted document (for insert operations).
  • error - Error message if the operation fails.

Dependencies

  • MongoDB database connection
  • MongoDB credentials for authentication

Troubleshooting

  • Common issues include invalid MongoDB connection credentials, incorrect collection names, or malformed query/update data.
  • Errors related to ObjectId conversion typically occur if the update key or fields expected to be ObjectId are not valid hexadecimal strings.
  • If the node throws an error about unsupported operations, ensure the operation parameter is set to 'update'.
  • Use the 'continue on fail' option to handle errors gracefully and continue processing other items.

Links

Discussion