MongoDBNg icon

MongoDBNg

Nextgen Find, insert and update documents in MongoDB

Overview

This node allows you to perform a Find operation on a MongoDB collection. It queries documents from the specified collection based on a user-defined MongoDB query and supports additional options such as limiting the number of results, skipping documents, sorting the output, and automatic conversion of _id fields to ObjectId type.

Typical use cases include:

  • Retrieving filtered data from a MongoDB database for further processing or analysis.
  • Fetching a subset of documents with pagination (using skip and limit).
  • Sorting query results by one or more fields.
  • Handling queries where the _id field is provided as a string but needs to be converted to an ObjectId for correct matching.

Example: Find all users born after 1950, limit results to 10, skip the first 5, and sort by birth date descending.

Properties

Name Meaning
Collection The name of the MongoDB collection to query.
Query A JSON-formatted MongoDB find query specifying the filter criteria.
Options Additional query options including:
- Limit Maximum number of documents to return; 0 means no limit.
- Skip Number of documents to skip in the result set (useful for pagination).
- Sort JSON object defining the sort order of the results, e.g., { "field": -1 } for descending order.
- _id as ObjectId Boolean flag indicating whether to automatically convert the _id field from string to ObjectId. If false, _id remains a string.

Output

The node outputs an array of JSON objects representing the documents returned by the MongoDB find query. Each item corresponds to one document from the collection.

  • The json field contains the document's fields and values.
  • If _id as ObjectId is enabled, the _id fields are converted back to strings for output consistency.
  • No binary data is output by this operation.

Dependencies

  • Requires a valid connection to a MongoDB database.
  • Needs credentials that provide access to the MongoDB instance (e.g., connection string or parameters).
  • Uses the official MongoDB Node.js driver internally.
  • The node expects the MongoDB server to be accessible and the specified database and collection to exist.

Troubleshooting

  • Invalid Query JSON: If the query JSON is malformed, the node will throw a parsing error. Ensure the query is valid JSON.
  • Collection Not Found: If the specified collection does not exist, the query will fail. Verify the collection name.
  • _id Conversion Issues: If _id as ObjectId is enabled but the _id string is not a valid ObjectId, the conversion will fail. Disable this option or ensure valid ObjectId strings.
  • Connection Errors: Failure to connect to MongoDB may occur due to incorrect credentials, network issues, or server unavailability. Check your credentials and network connectivity.
  • Limit and Skip Values: Negative or invalid values for limit or skip may cause errors or unexpected behavior. Use non-negative integers.

If the node is configured to continue on failure, errors during execution will be returned as part of the output JSON with an error property instead of stopping the workflow.

Links and References

Discussion