Drop Collection
Permanently deletes a collection and all of its documents from a MongoDB database.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
This operation is irreversible. All documents and indexes in the collection will be permanently deleted.
Inputs
- MongoDB Client Id - The client ID returned from the Connect node (optional if credentials are provided).
- Database Name - The name of the database containing the collection.
- Collection Name - The name of the collection to delete.
Options
- Credentials - Database credentials (Category 5) - optional if using Client ID from Connect node. This allows you to perform the operation without a separate Connect node.
How It Works
The Drop Collection node permanently removes a collection from a MongoDB database. When executed, the node:
- Validates that both database name and collection name are not empty
- Obtains a MongoDB client (either from client ID or by creating one from credentials)
- Accesses the specified database and collection
- Calls the drop operation to delete the entire collection
- All documents, indexes, and metadata associated with the collection are permanently removed
Requirements
- Either a valid client ID from Connect node OR database credentials
- Valid database name (non-empty)
- Valid collection name (non-empty)
- Appropriate permissions to drop collections in the database
- The collection must exist in the specified database
Error Handling
The node will return specific errors in the following cases:
- ErrInvalidArg - Database name or collection name is empty, or client/credentials are invalid
- ErrConnection - Cannot connect to MongoDB (when using credentials)
- Database not found error if the specified database doesn't exist
- Permission errors if the user doesn't have collection drop rights
- Collection operation errors if the drop fails
Usage Notes
- This operation is permanent and cannot be undone
- All documents in the collection are deleted
- All indexes on the collection are also removed
- Dropping a non-existent collection may result in an error
- Consider backing up data before dropping collections
- You can use either the client ID approach or direct credentials approach
- The database remains after the collection is dropped
Safety Best Practices
- Always confirm the collection name before dropping
- Never drop collections in production without proper approval
- Implement confirmation steps in your automation flows
- Consider archiving or exporting data before deletion
- Use appropriate user permissions to prevent accidental deletions
- Test drop operations in development environments first
- Document collection drop operations in your automation logs
Example Usage
Scenario 1: Drop a collection using Connect node
- Connect node → Client Id
- Drop Collection:
- MongoDB Client Id: (from Connect)
- Database Name: "myapp"
- Collection Name: "temp_data"
Scenario 2: Drop collection using direct credentials
- Drop Collection:
- MongoDB Client Id: (leave empty)
- Database Name: "legacy_system"
- Collection Name: "archived_logs"
- Credentials: (select database credential)
Scenario 3: Safe drop with verification
Set Variable:
- db_name = "testing"
- collection_name = "test_results"
Show Collections:
- Database Name: {db_name}
- Output: collections
If collections includes collection_name:
If db_name contains "test" or "dev":
Drop Collection:
- Database Name: {db_name}
- Collection Name: {collection_name}
Log: "Collection dropped successfully"
Else:
Log: "Cannot drop collection in production database"
Else:
Log: "Collection does not exist"
Scenario 4: Cleanup old collections
Connect → Client Id
Show Collections:
- Database Name: "analytics"
- Output: collections
For Each collection in collections:
If collection starts with "temp_":
Drop Collection:
- Database Name: "analytics"
- Collection Name: {collection}
Log: "Dropped temporary collection: " + collection
Disconnect
Common Use Cases
- Cleanup: Remove temporary or test collections after processing
- Reset: Clear all data in a collection by dropping and recreating it
- Testing: Clean up test collections between test runs
- Migration: Remove obsolete collections from legacy systems
- Space Management: Free up storage by removing unused collections
- Data Refresh: Drop and recreate collections for fresh data imports
Common Errors
Empty Database Name:
- Cause: Database name input is empty or not provided
- Solution: Provide a valid, non-empty database name
Empty Collection Name:
- Cause: Collection name input is empty or not provided
- Solution: Provide a valid, non-empty collection name
Collection Not Found:
- Cause: The collection doesn't exist in the specified database
- Solution: Verify the collection name is correct using Show Collections node
Permission Denied:
- Cause: User doesn't have permission to drop collections
- Solution: Ensure the database user has appropriate privileges (dbAdmin or dbOwner role)
Database Does Not Exist:
- Cause: The specified database doesn't exist
- Solution: Verify the database name is correct
Alternative to Dropping
Instead of dropping a collection, you might consider:
- Delete All Documents: Use Delete Document with an empty filter to remove all documents while preserving indexes
- Archive: Move data to an archive collection before dropping
- Rename: Rename the collection for later review instead of immediate deletion
Related Nodes
- Create Collection - Create a new collection
- Show Collections - List all collections in a database
- Delete Document - Delete specific documents without dropping the collection
- Drop Database - Delete the entire database including all collections