List Databases
Retrieves a list of all databases available on the MongoDB server along with their metadata.
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.
Inputs
- MongoDB Client Id - The client ID returned from the Connect node (optional if credentials are provided).
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.
Output
- DB List - An object containing information about all databases on the server, including:
- databases - Array of database objects, each containing:
- name - The name of the database
- sizeOnDisk - Size of the database in bytes
- empty - Boolean indicating if the database is empty
- totalSize - Total size of all databases in bytes
- totalSizeMb - Total size in megabytes (if applicable)
- ok - Status indicator (1 for success)
- databases - Array of database objects, each containing:
How It Works
The List Databases node queries the MongoDB server for database information. When executed, the node:
- Obtains a MongoDB client (either from client ID or by creating one from credentials)
- Calls the ListDatabases command with an empty filter
- Retrieves metadata about all databases the user has access to
- Returns the complete database list with size and status information
- Stores the result in the specified output variable
Requirements
- Either a valid client ID from Connect node OR database credentials
- Appropriate permissions to list databases on the MongoDB server
- The user must have the listDatabases privilege
Error Handling
The node will return specific errors in the following cases:
- ErrInvalidArg - Client ID or credentials are invalid
- ErrConnection - Cannot connect to MongoDB (when using credentials)
- Permission errors if the user doesn't have database listing rights
Usage Notes
- System databases (admin, local, config) are included in the list
- The size information reflects the current disk usage
- Empty databases (with no data) may still show a small size due to metadata
- You can use either the client ID approach or direct credentials approach
- The output is useful for monitoring, reporting, and automation decisions
- Database names are returned as they exist on the server (case-sensitive)
Output Format Example
{
"databases": [
{
"name": "admin",
"sizeOnDisk": 40960,
"empty": false
},
{
"name": "sales_data",
"sizeOnDisk": 2097152,
"empty": false
},
{
"name": "test",
"sizeOnDisk": 0,
"empty": true
}
],
"totalSize": 2138112,
"ok": 1
}
Example Usage
Scenario 1: List all databases using Connect node
- Connect node → Client Id
- List Databases:
- MongoDB Client Id: (from Connect)
- Output: db_list
- Log:
{{db_list}}
Scenario 2: List databases using direct credentials
- List Databases:
- MongoDB Client Id: (leave empty)
- Credentials: (select database credential)
- Output: databases
- Process the database list
Scenario 3: Find databases by pattern
List Databases → db_list
For Each database in db_list.databases:
If database.name starts with "prod_":
Log: "Production database found: " + database.name
Log: "Size: " + database.sizeOnDisk + " bytes"
Scenario 4: Monitor database sizes
List Databases → db_list
Set Variable:
- total_mb = db_list.totalSize / (1024 * 1024)
If total_mb > 10000:
Send Alert: "Total database size exceeds 10GB: " + total_mb + "MB"
Common Use Cases
- Monitoring: Track database sizes and growth over time
- Inventory: Get a complete list of all databases on the server
- Validation: Verify that required databases exist
- Cleanup: Identify empty or obsolete databases for removal
- Reporting: Generate database usage reports
- Automation: Make decisions based on database existence or size
- Auditing: Log all databases for compliance purposes
Common Errors
Permission Denied:
- Cause: User doesn't have permission to list databases
- Solution: Ensure the user has the listDatabases action privilege
Invalid Client:
- Cause: Client ID doesn't exist or connection is closed
- Solution: Verify the Connect node executed successfully and the client ID is valid
Processing the Output
Access all database names:
db_list.databases.map(db => db.name)
Find a specific database:
db_list.databases.find(db => db.name === "mydb")
Calculate total size in MB:
db_list.totalSize / (1024 * 1024)
Filter non-empty databases:
db_list.databases.filter(db => !db.empty)
Related Nodes
- Create Database - Create a new database
- Drop Database - Delete a database
- Show Collections - List collections within a specific database