Overview
This node connects to a specified database (either MySQL or MongoDB) and retrieves the list of tables (for MySQL) or collections (for MongoDB) within the selected database. It is useful when you want to dynamically fetch database schema information for further processing or automation workflows, such as generating reports, syncing data, or validating database structure.
Practical examples:
- Automatically listing all tables in a MySQL database before performing data extraction.
- Fetching all collections from a MongoDB database to iterate over them for backup or migration tasks.
Properties
| Name | Meaning |
|---|---|
| Database Type | Select the type of database to connect to. Options: MySQL, MongoDB |
| Host | The host address of the database server. For MongoDB Atlas, use the connection string format like mongodb+srv://<username>:<password>@cluster-url |
| Port | The port number to connect to the database. For MongoDB Atlas, this can be left empty |
| Username | The username credential for authenticating with the database |
| Password | The password credential for authenticating with the database |
| Database Name | The name of the specific database to connect to |
Output
The node outputs an array of items where each item contains a JSON object with either:
For MySQL:
{ "tableName": "name_of_table" }Each item represents one table name retrieved from the connected MySQL database.
For MongoDB:
{ "collectionName": "name_of_collection" }Each item represents one collection name retrieved from the connected MongoDB database.
If an error occurs during connection or querying, the output will contain an item with an error message in the JSON field:
{
"error": "Error connecting to database: <error_message>"
}
The node does not output binary data.
Dependencies
- Requires the
mysql2library for MySQL connections. - Requires the official
mongodbNode.js driver for MongoDB connections. - Needs proper network access to the target database server.
- Requires valid credentials (host, port, username, password, database name) to establish the connection.
Troubleshooting
Common issues:
- Incorrect host or port leading to connection timeouts.
- Invalid username or password causing authentication failures.
- Unsupported database type selection.
- Missing or incorrect database name.
- Network restrictions or firewall blocking access to the database server.
Error messages:
"Error connecting to database: <message>": Indicates failure during connection or query execution. Check credentials, network connectivity, and database availability."Unsupported database type": The selected database type is not supported by the node; ensure only "MySQL" or "MongoDB" are chosen.
Resolution tips:
- Verify all input properties carefully.
- For MongoDB Atlas, use the full connection string in the Host property and leave Port empty.
- Ensure the database user has sufficient privileges to list tables or collections.
- Confirm that the database server allows remote connections if running n8n remotely.