Overview
This node provides integration with MongoDB databases, allowing users to perform various operations such as finding, inserting, updating, aggregating, and deleting documents within specified collections. The "Delete" operation specifically enables users to remove multiple documents from a MongoDB collection based on a JSON-formatted query filter.
Common scenarios for using the Delete operation include cleaning up outdated records, removing test data, or deleting entries that meet certain criteria (e.g., all users inactive since a specific date).
Example:
Delete all documents in the "users" collection where the "birth" field is greater than "1950-01-01".
Properties
| Name | Meaning |
|---|---|
| Collection | The name of the MongoDB collection from which documents will be deleted. |
| Delete Query (JSON Format) | A JSON object representing the MongoDB delete query filter to select documents to delete. Example: { "birth": { "$gt": "1950-01-01" } } |
Output
The output JSON contains an object with a single property:
deletedCount: The number of documents that were deleted by the operation.
Example output:
[
{
"deletedCount": 5
}
]
This indicates that 5 documents matched the query and were removed from the collection.
Dependencies
- Requires a valid connection to a MongoDB database.
- Needs credentials providing access to the MongoDB instance (such as a connection string or other authentication method).
- 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 JSON in Delete Query: If the JSON query is malformed, the node will throw a parsing error. Ensure the query is valid JSON.
- Connection Issues: Errors connecting to MongoDB may occur if credentials are incorrect or the server is unreachable. Verify network connectivity and credential correctness.
- Collection Does Not Exist: If the specified collection does not exist, the operation may fail or delete zero documents.
- Permission Denied: Insufficient permissions to delete documents can cause errors. Ensure the provided credentials have delete privileges.
- Empty Query: Using an empty query
{}will delete all documents in the collection. Use with caution.
If the node is set to continue on failure, errors will be returned as part of the output JSON with an error property describing the issue.
Links and References
- MongoDB Delete Documentation
- MongoDB Query Selectors
- n8n MongoDB Integration Docs (for general usage guidance)