MongoDB icon

MongoDB

Find, insert and update documents in MongoDB

Overview

This node allows you to interact with a MongoDB database by performing various operations such as finding, inserting, updating, and deleting documents within specified collections. It is particularly useful for workflows that require querying or manipulating data stored in MongoDB without writing custom code.

A common use case is retrieving filtered datasets from a MongoDB collection based on complex queries, optionally sorting and projecting specific fields. For example, you might use the "Find" operation to get all users born after 1950, sorted by their last name, and only retrieve their names and emails.

Properties

Name Meaning
Collection The name of the MongoDB collection to operate on.
Query (JSON Format) A JSON object defining the MongoDB query filter to select documents. Example: { "birth": { "$gt": "1950-01-01" } }
Options Additional query options including:
- Limit: Maximum number of documents to return (0 means no limit).
- Skip: Number of documents to skip.
- Sort (JSON Format): JSON defining sort order, e.g., { "field": -1 }.
- Projection (JSON Format): JSON defining which fields to include or exclude, e.g., { "_id": 0, "field": 1 }.

Output

The output consists of an array of items where each item’s json property contains one document retrieved from the MongoDB collection matching the query criteria.

  • Each document is represented as a JSON object with its fields.
  • If multiple documents match, each will be output as a separate item.
  • In case of errors during execution (and if the node is set to continue on failure), the output item will contain an error field describing the issue.
  • This node does not output binary data.

Dependencies

  • Requires a MongoDB database connection configured via credentials containing the necessary authentication details (e.g., connection string or parameters).
  • The node uses the official MongoDB Node.js driver to connect and perform operations.
  • No additional external services are required beyond access to the MongoDB instance.

Troubleshooting

  • Invalid JSON in Query or Options: Since the query, sort, and projection fields expect valid JSON, syntax errors here will cause failures. Ensure these inputs are correctly formatted JSON objects.
  • Invalid ObjectId Strings: If the query includes an _id field as a string, it is automatically converted to a MongoDB ObjectId. Providing invalid ObjectId strings will cause errors.
  • Connection Issues: Errors connecting to the MongoDB server may occur if credentials are incorrect or the server is unreachable. Verify connection details and network accessibility.
  • Empty Results: If no documents match the query, the output will be empty. Double-check your query filters.
  • Continue On Fail Behavior: When enabled, errors in processing individual items do not stop execution but instead output error messages per item.

Links and References

Discussion