Create Database
Creates a new MongoDB database. In MongoDB, databases are created implicitly when you first store data in them, so this node creates a database by creating and immediately removing a temporary collection.
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).
- Database Name - The name of the database to create.
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
MongoDB creates databases lazily - a database doesn't physically exist until it contains data. This node creates a database by:
- Validates the database name is not empty
- Obtains a MongoDB client (either from client ID or by creating one from credentials)
- Accesses the database with the specified name
- Creates a temporary collection called "defaultcollection"
- Inserts a temporary document into the collection
- Immediately deletes the temporary document
- The database now exists in MongoDB's database list
Requirements
- Either a valid client ID from Connect node OR database credentials
- A valid database name (non-empty)
- Appropriate permissions to create databases on the MongoDB server
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 creation rights
Usage Notes
- MongoDB database names are case-sensitive
- Database names cannot contain spaces or special characters like
/\. "$*<>:|? - The database will appear in the database list after this operation
- If a database with the same name already exists, this operation is harmless (idempotent)
- You can use either the client ID approach or direct credentials approach
- The temporary collection creation/deletion happens automatically and atomically
Database Naming Best Practices
- Use lowercase names for consistency
- Use underscores instead of spaces or hyphens
- Keep names descriptive but concise
- Avoid reserved names like "admin", "local", "config"
Example Usage
Scenario 1: Create database using Connect node
- Connect node → Client Id
- Create Database:
- MongoDB Client Id: (from Connect)
- Database Name: "sales_data"
Scenario 2: Create database using direct credentials
- Create Database:
- MongoDB Client Id: (leave empty)
- Database Name: "inventory"
- Credentials: (select database credential)
Scenario 3: Create multiple databases
Connect → Client Id
Create Database:
- Client Id: (from Connect)
- Database Name: "production"
Create Database:
- Client Id: (from Connect)
- Database Name: "staging"
Create Database:
- Client Id: (from Connect)
- Database Name: "development"
Disconnect
Common Use Cases
- Environment Setup: Create separate databases for development, staging, and production
- Multi-tenant Applications: Create a database per customer or tenant
- Data Segregation: Create databases for different departments or projects
- Testing: Create temporary databases for automated testing
- Migration: Create target databases before data migration
Common Errors
Empty Database Name:
- Cause: Database name input is empty or not provided
- Solution: Provide a valid, non-empty database name
Invalid Characters in Name:
- Cause: Database name contains prohibited characters
- Solution: Use only alphanumeric characters, underscores, and hyphens
Permission Denied:
- Cause: User doesn't have permission to create databases
- Solution: Ensure the database user has appropriate privileges (dbAdmin or root role)
Related Nodes
- Drop Database - Delete a database
- List Databases - View all databases on the server
- Create Collection - Create a collection within a database