MongoDB Pro icon

MongoDB Pro

Find, insert and update documents in MongoDB

Overview

The node enables querying documents from a MongoDB collection using the "Find" operation. It allows users to specify a MongoDB query in JSON format and supports additional options such as limiting the number of results, skipping documents, sorting, and projecting specific fields. This node is useful for retrieving data from MongoDB databases in workflows where filtering, sorting, or partial field retrieval is required.

Practical examples:

  • Fetch all user documents born after 1950.
  • Retrieve the first 10 orders sorted by date descending.
  • Get only the name and email fields of customers matching certain criteria.

Properties

Name Meaning
Collection The MongoDB collection to query documents from.
Query A JSON-formatted MongoDB find query specifying filter conditions (e.g., { "age": { "$gt": 30 } }).
Options Additional query options including:
- Limit Maximum number of documents to return; 0 means no limit.
- Skip Number of documents to skip before returning results.
- Sort JSON defining sort order, e.g., { "field": -1 } for descending sort on "field".
- Projection JSON defining which fields to include or exclude in the result set, e.g., { "_id": 0, "name": 1 }.

Output

The output consists of an array of items, each containing a json property with one document retrieved from the MongoDB collection matching the query and options. Each item corresponds to one document found.

  • The json object contains the fields of the MongoDB document.
  • If multiple documents are returned, each document is output as a separate item.
  • In case of errors during execution, the output item will contain an error field describing the issue.

No binary data is output by this operation.

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 internally.
  • The user must have access rights to the specified database and collection.

Troubleshooting

  • Common issues:

    • Invalid JSON syntax in the Query, Sort, or Projection fields can cause parsing errors.
    • Specifying a non-existent collection or database will result in connection or query errors.
    • Using incorrect field names or types in the query may lead to empty results or errors.
  • Error messages:

    • "SyntaxError" related to JSON parsing indicates malformed JSON input; verify and correct the JSON format.
    • "Database does not exist" or "Collection not found" suggests misconfiguration of database or collection names.
    • MongoDB driver errors about authentication failure indicate invalid or missing credentials.
  • Resolution tips:

    • Validate JSON inputs with external tools before entering them.
    • Confirm database and collection names are correct and accessible.
    • Ensure credentials are properly configured and tested.

Links and References

Discussion