Find
AI-generatedOverview
This node performs various MongoDB operations on specified collections within a database. It is useful for integrating MongoDB data manipulation directly into n8n workflows, enabling automation of database queries and updates without writing custom code.
Common scenarios include:
- Retrieving documents from a collection with filtering, sorting, skipping, and limiting options.
- Aggregating data using MongoDB aggregation pipelines.
- Updating or replacing documents based on query criteria.
- Inserting multiple new documents at once.
- Deleting specific documents matching a query.
For example, you can use the "Find" operation to fetch user records born after 1950, sorted by last name, or use "Aggregate" to compute statistics like average sales per region.
Properties
| Name | Meaning |
|---|---|
| Collection | The MongoDB collection on which the operation will be performed. |
| Query (JSON Format) | A JSON object defining the MongoDB query filter to select documents. Required for find, update, replaceOne, deleteOne, and aggregate operations. Example: { "birth": { "$gt": "1950-01-01" } } |
| Options | Additional query options available for "find" and "aggregate" operations: |
| - Limit | Maximum number of documents to return. Use 0 for no limit. Default is 50. |
| - Skip | Number of documents to skip in the result set. Default is 0. |
| - Sort (JSON Format) | JSON object defining the sort order of results. Example: { "field": -1 } where -1 means descending order. |
Output
The node outputs an array of JSON objects representing the documents returned or affected by the operation:
- For Find and Aggregate operations, the output contains the matched documents as JSON objects.
- For Update, ReplaceOne, and DeleteOne, the output returns the input items unchanged or the replaced document.
- For Insert, the output contains the inserted documents.
No binary data output is produced by this node.
Dependencies
- Requires a valid MongoDB connection string and database name provided via credentials.
- The node depends on the official MongoDB Node.js driver to connect and perform operations.
- Proper permissions on the MongoDB server are necessary for the selected operations.
Troubleshooting
- Invalid JSON in Query or Options: The node expects JSON strings for query and sort parameters. Malformed JSON will cause parsing errors. Ensure correct JSON syntax.
- Connection Errors: If the node cannot connect to MongoDB, verify the connection string, network access, and credentials.
- Operation Failures: Errors during operations (e.g., invalid queries, permission issues) will throw exceptions unless "Continue On Fail" is enabled, in which case error messages are returned in the output.
- Empty Results: If no documents match the query, the output will be empty. Check query correctness and collection contents.