Skip to main content

Show Collections

Retrieves a list of all collection names in a specified 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.
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 list collections from.

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

  • Collections - An array of collection names in the specified database.

How It Works

The Show Collections node queries a MongoDB database for its collection names. 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 ListCollectionNames command
  5. Retrieves all collection names that the user has access to
  6. Returns the collection names as an array
  7. Stores the result in the specified output variable

Requirements

  • Either a valid client ID from Connect node OR database credentials
  • Valid database name (non-empty) - the database must exist
  • Appropriate permissions to list collections in the database

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)
  • Database not found error if the specified database doesn't exist
  • Permission errors if the user doesn't have collection listing rights

Usage Notes

  • The output is an array of collection name strings
  • System collections (those starting with "system.") are included in the list
  • Empty databases return an empty array
  • Collection names are returned as they exist on the server (case-sensitive)
  • You can use either the client ID approach or direct credentials approach
  • The output can be used to iterate through collections or check for existence

Output Format Example

[
"users",
"products",
"orders",
"sessions",
"audit_logs"
]

Example Usage

Scenario 1: List collections using Connect node

  1. Connect node → Client Id
  2. Show Collections:
    • MongoDB Client Id: (from Connect)
    • Database Name: "ecommerce"
    • Output: collections
  3. Log: {{collections}}

Scenario 2: List collections using direct credentials

  1. Show Collections:
    • MongoDB Client Id: (leave empty)
    • Database Name: "inventory"
    • Credentials: (select database credential)
    • Output: collection_list

Scenario 3: Check if a collection exists

Show Collections:
- Database Name: "myapp"
- Output: collections

Set Variable:
- collection_exists = collections.includes("users")

If collection_exists:
Log: "Users collection exists"
Else:
Create Collection:
- Database Name: "myapp"
- Collection Name: "users"

Scenario 4: Process all collections in a database

Connect → Client Id

Show Collections:
- Database Name: "analytics"
- Output: collections

For Each collection_name in collections:
Log: "Processing collection: " + collection_name

Read All:
- Database Name: "analytics"
- Collection Name: `{{collection_name}}`
- Output: documents

Log: "Found " + documents.length + " documents"

Disconnect

Scenario 5: Find collections by pattern

Show Collections:
- Database Name: "reporting"
- Output: all_collections

Set Variable:
- report_collections = []

For Each col in all_collections:
If col starts with "report_":
Append to report_collections: col

Log: "Report collections: " + report_collections.join(", ")

Scenario 6: Count collections in database

Show Collections:
- Database Name: "production"
- Output: collections

Set Variable:
- collection_count = collections.length

Log: "Database has " + collection_count + " collections"

If collection_count > 100:
Send Alert: "Database has too many collections"

Common Use Cases

  • Inventory: Get a complete list of all collections in a database
  • Validation: Verify that required collections exist before operations
  • Migration: Discover collections that need to be migrated
  • Monitoring: Track the number and names of collections over time
  • Automation: Dynamically process all collections in a database
  • Cleanup: Identify collections for archival or deletion
  • Documentation: Generate database schema documentation

Common Errors

Empty Database Name:

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

Database Does Not Exist:

  • Cause: The specified database doesn't exist
  • Solution: Verify the database name or create it first using Create Database

Permission Denied:

  • Cause: User doesn't have permission to list collections
  • Solution: Ensure the user has the listCollections action privilege

Invalid Client:

  • Cause: Client ID doesn't exist or connection is closed
  • Solution: Verify the Connect node executed successfully

Working with the Output

Check if collection exists:

collections.includes("my_collection")

Filter collections by prefix:

collections.filter(col => col.startsWith("temp_"))

Count collections:

collections.length

Get first collection:

collections[0]

Sort collections alphabetically:

collections.sort()
  • Create Collection - Create a new collection
  • Drop Collection - Delete a collection
  • List Databases - List all databases on the server
  • Read All - Read all documents from a specific collection