Skip to main content

Drop Database

Permanently deletes a MongoDB database and all of its collections and documents.

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.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

warning

This operation is irreversible. All data in the database 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 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 Database node permanently removes a database from the MongoDB server. When executed, the node:

  1. Validates that the database name is not empty
  2. Obtains a MongoDB client (either from client ID or by creating one from credentials)
  3. Accesses the specified database
  4. Calls the drop operation to delete the entire database
  5. All collections and documents within the database are permanently removed

Requirements

  • Either a valid client ID from Connect node OR database credentials
  • A valid database name (non-empty)
  • Appropriate permissions to drop databases on the MongoDB server
  • The database must exist (attempting to drop a non-existent database will succeed without error)

Error Handling

The node will return specific errors in the following cases:

  • ErrInvalidArg - Database name is empty or client/credentials are invalid
  • ErrConnection - Cannot connect to MongoDB (when using credentials)
  • Permission errors if the user doesn't have database drop rights

Usage Notes

  • This operation is permanent and cannot be undone
  • All collections and documents in the database are deleted
  • The operation succeeds even if the database doesn't exist
  • System databases (admin, local, config) should not be dropped
  • Always verify the database name before executing this operation
  • Consider backing up data before dropping databases
  • You can use either the client ID approach or direct credentials approach

Safety Best Practices

  • Always confirm the database name before dropping
  • Never drop databases in production without proper approval
  • Implement confirmation steps in your automation flows
  • Use version control for database schemas to enable recreation
  • Consider archiving data before deletion
  • Test drop operations in development environments first
  • Use appropriate user permissions to prevent accidental deletions

Example Usage

Scenario 1: Drop a test database using Connect node

  1. Connect node → Client Id
  2. Drop Database:
    • MongoDB Client Id: (from Connect)
    • Database Name: "test_database"

Scenario 2: Drop database using direct credentials

  1. Drop Database:
    • MongoDB Client Id: (leave empty)
    • Database Name: "old_project_data"
    • Credentials: (select database credential)

Scenario 3: Safe drop with confirmation

Set Variable:
- database_to_drop: "temporary_db"

Condition:
- If: database_to_drop contains "test" or "temp" or "dev"
- Then:
Drop Database:
- Database Name: {database_to_drop}
- Else:
Log: "Cannot drop production database"
Throw Error

Common Use Cases

  • Cleanup: Remove temporary or test databases after automation runs
  • Reset: Clear all data to start fresh in development environments
  • Decommission: Remove databases from retired projects or customers
  • Testing: Clean up test databases between test runs
  • Space Management: Remove obsolete databases to free up storage

Common Errors

Empty Database Name:

  • Cause: Database name input is empty or not provided
  • Solution: Provide a valid, non-empty database name

Permission Denied:

  • Cause: User doesn't have permission to drop databases
  • Solution: Ensure the database user has appropriate privileges (dbAdmin, dbOwner, or root role)

Database In Use:

  • Cause: Active connections or locks on the database
  • Solution: Close all active connections to the database before dropping
  • Create Database - Create a new database
  • List Databases - View all databases on the server
  • Drop Collection - Delete individual collections instead of entire database

Important Warnings

  • There is no confirmation prompt - the operation executes immediately
  • Recovery is only possible from backups
  • All indexes, users, and metadata associated with the database are also deleted
  • Applications connected to the database will encounter errors after the drop