Mongo DB OID icon

Mongo DB OID

Find, insert and update documents in MongoDB

Overview

This node operation performs a 'Find And Replace' action on documents within a specified MongoDB collection. It replaces documents that match a given update key with new data provided in the input. This operation is useful for scenarios where you need to update entire documents based on a unique identifier, such as replacing user profiles, product details, or configuration records in a MongoDB database.

Use Case Examples

  1. Replacing a user document in a 'users' collection based on user ID.
  2. Updating a product entry in an inventory collection by replacing the entire document using a product SKU as the update key.

Properties

Name Meaning
Collection The MongoDB collection where the documents will be found and replaced.
Update Key The property name used to identify which documents should be replaced. Typically this is '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 a new document if no matching document is found.
Options Additional options for the operation, including date fields to parse as MongoDB Date type, whether to use dot notation for accessing date fields, and fields to parse as MongoDB ObjectId type.

Output

JSON

  • _id - The MongoDB document identifier, converted to ObjectId if applicable.
    - Fields included in the replaced document as specified by the 'Fields' input.
  • error - Error message if the operation fails for a particular item and 'continueOnFail' is enabled.

Dependencies

  • MongoDB database connection with appropriate credentials

Troubleshooting

  • Common issues include invalid ObjectId format for the update key when it is '_id', which should be a valid MongoDB ObjectId string.
  • Errors may occur if the specified collection does not exist or the database connection fails.
  • If 'continueOnFail' is not enabled, the node will throw errors immediately on failure; enabling it allows processing to continue with error details in output.

Discussion