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.

Output

The output is a JSON array where each element corresponds to a document or result returned by the operation performed on the MongoDB collection. The structure depends on the operation:

  • For find and aggregate, it returns an array of documents matching the query or aggregation pipeline.
  • For insert, it returns the inserted documents augmented with their generated IDs.
  • For update, findOneAndUpdate, and findOneAndReplace, it returns the updated/replaced documents.
  • For delete, it returns an object with a deletedCount property indicating how many documents were deleted.
  • If errors occur and "continue on fail" is enabled, the output contains objects with an error property describing the issue.

If the node outputs binary data (not shown in this code), it would represent files or media stored in MongoDB, but this node focuses on JSON document data.

Dependencies

  • Requires a MongoDB instance accessible via connection string or parameters.
  • Needs credentials providing access to the MongoDB database.
  • Uses BSON and MongoDB Node.js driver libraries internally.
  • No additional external services are required beyond MongoDB itself.

Troubleshooting

  • Common issues:

    • Invalid or unreachable MongoDB connection string or credentials.
    • Specified database or collection does not exist.
    • Malformed queries or aggregation pipelines causing parsing errors.
    • Using incorrect types for _id fields (string vs ObjectId).
    • Operations not supported by the node.
  • Error messages:

    • "Database \"<name>\" does not exist": Check the database name in credentials.
    • Errors related to query parsing: Ensure queries are valid Extended JSON.
    • "The operation \"<operation>\" is not supported!": Use one of the supported operations.
    • Connection failures: Verify network access and authentication details.

Enabling "continue on fail" allows the workflow to proceed even if some operations fail, returning error details in the output.

Links and References

Discussion