Mongo DB OID icon

Mongo DB OID

Find, insert and update documents in MongoDB

Overview

This node enables interaction with a MongoDB database, allowing users to perform various operations such as aggregation, querying, inserting, updating, and deleting documents within specified collections. The "Aggregate" operation specifically executes a MongoDB aggregation pipeline query, which is a powerful framework for data aggregation modeled on the concept of data processing pipelines.

Common scenarios where this node is beneficial include:

  • Performing complex data transformations and computations on MongoDB collections.
  • Filtering, grouping, sorting, and reshaping data before further processing or analysis.
  • Combining multiple stages of data processing in a single query to optimize performance.

Practical example: Suppose you have a collection of sales records and want to calculate total sales per product category for the last year. Using the Aggregate operation, you can define a pipeline that filters records by date, groups them by category, sums the sales amounts, and sorts the results.

Properties

Name Meaning
Collection The name of the MongoDB collection on which the aggregation pipeline will be executed.
Query The MongoDB aggregation pipeline expressed as a JSON array. This defines the sequence of stages to process the data. Example stages include $match, $group, $sort, etc.

Output

The output is an array of JSON objects representing the documents returned by the aggregation pipeline. Each object corresponds to a document resulting from the pipeline's processing stages.

If the aggregation pipeline includes stages that produce binary data (e.g., GridFS operations), the node would handle it accordingly, but based on the provided code, the output is standard JSON documents.

Dependencies

  • Requires a MongoDB database connection configured via credentials that provide necessary authentication details (such as an API key or connection string).
  • The node uses the official MongoDB Node.js driver and BSON utilities internally.
  • No additional external services are required beyond access to the MongoDB instance.

Troubleshooting

  • Invalid Aggregation Pipeline Syntax: If the JSON query is malformed or contains invalid stages, the node will throw an error. Ensure the pipeline is valid according to MongoDB's aggregation framework syntax.
  • Collection Does Not Exist: Specifying a non-existent collection will result in an error. Verify the collection name is correct.
  • Connection Issues: Errors related to authentication or network connectivity may occur if credentials are incorrect or the MongoDB server is unreachable.
  • ObjectId Conversion: If the pipeline references _id fields as strings, the node attempts to convert them to ObjectId instances. Incorrect formats may cause errors.
  • To continue execution despite errors, enable the node's "Continue On Fail" option; otherwise, errors will stop the workflow.

Links and References

Discussion