Overview
This node allows users to interact with a MongoDB database by performing various operations such as finding, inserting, updating, deleting, and aggregating documents within specified collections. It is particularly useful for automating workflows that require database manipulation without writing custom code.
For the Delete operation specifically, the node deletes multiple documents from a given MongoDB collection based on a user-defined query expressed in JSON format. This is beneficial when you want to remove records matching certain criteria, for example, deleting all users born before a specific date or removing outdated logs.
Practical example:
- Delete all documents in the "users" collection where the "birth" field is greater than "1950-01-01".
- Remove all entries from a "sessions" collection where the session has expired.
Properties
Name | Meaning |
---|---|
Collection | The name of the MongoDB collection where the delete operation will be performed. |
Delete Query (JSON Format) | A JSON-formatted MongoDB query specifying which documents to delete. For example: { "birth": { "$gt": "1950-01-01" } } |
Output
The output is an array of JSON objects, each corresponding to one execution item. For the Delete operation, each output JSON object contains:
deletedCount
: The number of documents that were deleted by the operation.
Example output JSON:
{
"deletedCount": 5
}
This indicates that 5 documents matched the query and were removed from the collection.
The node does not output binary data.
Dependencies
- Requires a MongoDB database connection.
- Requires an API key credential or authentication token configured in n8n to connect securely to the MongoDB instance.
- Uses the official MongoDB Node.js driver internally.
- The node expects valid MongoDB connection credentials and database information to be set up in n8n.
Troubleshooting
Common issues:
- Invalid JSON in the Delete Query property can cause parsing errors.
- Specifying a non-existent collection or database will result in connection or query errors.
- Insufficient permissions on the MongoDB user may prevent deletion.
- Connection failures due to incorrect credentials or network issues.
Error messages and resolutions:
"SyntaxError: Unexpected token ..."
— Check and correct the JSON syntax in the Delete Query."Database \"X\" does not exist"
— Verify the database name in credentials."Collection not found"
or similar — Ensure the collection name is correct."Authentication failed"
— Confirm the API key or credentials have proper access rights.- If the node throws errors but "Continue On Fail" is enabled, error details will appear in the output JSON under an
error
field.