Mongo DB OID icon

Mongo DB OID

Find, insert and update documents in MongoDB

Overview

This node enables interaction with a MongoDB database to perform various document operations such as querying, inserting, updating, replacing, deleting, and aggregating data within specified collections. It is useful in scenarios where you need to integrate MongoDB data manipulation into automated workflows without writing custom code.

Practical examples include:

  • Fetching documents matching certain criteria from a collection.
  • Inserting multiple new documents into a collection.
  • Updating or replacing existing documents based on a key field.
  • Deleting documents that match a query.
  • Running aggregation pipelines for complex data processing.

Properties

Name Meaning
Collection The name of the MongoDB collection to operate on.

(Note: Although the bundled code supports many operations like aggregate, find, insert, update, delete, etc., only the "Collection" property was provided for this summary.)

Output

The output is an array of JSON objects representing the results of the MongoDB operation performed:

  • For find and aggregate operations, it returns the matched documents as JSON objects.
  • For insert, it returns the inserted documents augmented with their generated IDs.
  • For update, replace, and delete operations, it returns information about the affected documents or counts.
  • If errors occur and the node is configured to continue on failure, the output contains error messages per item.
  • The node does not output binary data.

Dependencies

  • Requires a valid connection to a MongoDB instance, authenticated via credentials containing either a connection string or parameters to build one.
  • Uses the official MongoDB Node.js driver and BSON utilities.
  • Requires n8n credentials setup for MongoDB access.

Troubleshooting

  • Common issues:
    • Incorrect or missing MongoDB credentials leading to connection failures.
    • Specifying a non-existent database or collection.
    • Malformed queries or aggregation pipelines causing parsing errors.
    • Using invalid ObjectId strings without proper conversion.
  • Error messages:
    • "Database \"<name>\" does not exist" indicates the specified database is not found; verify database name.
    • Errors during query parsing usually mean the input JSON is invalid or improperly formatted.
    • Operation not supported errors occur if an unsupported operation string is used.
  • To resolve errors, ensure correct credentials, validate all input JSON parameters, and use supported operations.

Links and References

Discussion