Mongo DB OID icon

Mongo DB OID

Find, insert and update documents in MongoDB

Overview

This node enables interaction with MongoDB databases, specifically supporting operations such as finding, inserting, updating, replacing, and deleting documents within a specified collection. The "Update" operation allows users to update existing documents based on a key property, with options to insert new documents if no match is found (upsert). This node is beneficial in scenarios where you need to synchronize data between systems, update records dynamically, or maintain MongoDB collections programmatically.

For example, you might use this node to update user profiles in a MongoDB collection by matching on a unique user ID, or to replace entire documents when certain conditions are met.

Properties

Name Meaning
Collection The name of the MongoDB collection where documents will be updated.
Update Key The property name used to identify which documents to update (e.g., "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 existing document matches the update key.
Options Additional options for the update operation:
- Date Fields Comma-separated list of fields that should be parsed as MongoDB Date type.
- Use Dot Notation Whether to use dot notation to access nested date fields.
- OID Fields Comma-separated list of fields that should be parsed as MongoDB ObjectId type.

Output

The output is an array of JSON objects representing the documents after the update operation. Each object corresponds to an input item processed by the node. If errors occur during processing and the node is configured to continue on failure, the error message will be included in the json field of the respective item under an error property.

No binary data is output by this node.

Dependencies

  • Requires a MongoDB database connection, authenticated via an API key credential or similar authentication method.
  • The node depends on the official MongoDB Node.js driver and BSON utilities for handling ObjectId and Date types.
  • Proper configuration of the MongoDB credentials in n8n is necessary, including database name and connection string or parameters.

Troubleshooting

  • Common Issues:

    • Incorrect collection name or database name can cause failures.
    • Malformed query or update fields may result in errors.
    • Using an invalid ObjectId format in the update key can cause exceptions.
    • Missing or incorrect credentials will prevent connection to MongoDB.
  • Error Messages:

    • "Database \"<name>\" does not exist": Verify the database name in credentials.
    • Errors related to ObjectId conversion: Ensure the update key value is a valid ObjectId string if _id is used.
    • "The operation \"<operation>\" is not supported!": Indicates an unsupported operation was requested; verify the operation parameter.
  • To resolve errors, check the input parameters, ensure correct formatting of fields, and validate MongoDB connection settings.

Links and References

Discussion