Documentation

Collection Management

Collection Management

The Collection Management activity provides a comprehensive interface for creating new MongoDB collections and modifying existing ones. Configure all MongoDB collection options including schema validation, capped settings, time series, views, collation, and advanced features through an intuitive card-based layout.

Quick Start

Get started with collection management in VisuaLeaf:

  1. Right-click on a database in the sidebar and select "Create Collection"
  2. Enter a collection name in the Basic Configuration card
  3. Optionally configure validation rules in the Validation Configuration card
  4. For specialized collections, configure Time Series, Views, or Capped settings
  5. Click "Create Collection" to create, or "Apply Changes" to modify
Full Collection Management interface in Create mode showing the card-based layout with all configuration sections arranged in a 2-column grid
Video NCOL02 Complete Collection Management Walkthrough - Creating collections with validation, configuring time series collections, and modifying existing collection settings

Create vs Edit Mode

The Collection Management interface operates in two distinct modes with different available options:

Mode Available Options Indication
Create All options available - name, capped, storage engine, views, time series, collation, clustered index, encrypted fields Header shows "Create Collection"
Edit Limited options - validation rules, validation level/action, TTL, change stream images, comment Header shows "Modify: [collection name]" with yellow info banner
Edit mode interface showing the yellow info banner 'Only certain options can be modified after creation' with the reduced configuration options

Basic Configuration

The Basic Configuration card contains fundamental collection settings available during creation.

Field Description Required
Collection Name Unique name within the database. Shows real-time validation if name already exists. Yes
Comment Optional description attached to the collection metadata No
Capped Collection Enable fixed-size collection with automatic document rotation. Click "Configure" to set size/max. No

Capped Collection Configuration

When enabling capped collections, click the "Configure" button to open the Capped Configuration modal:

Option Description Required
Size (bytes) Maximum collection size. Required when capped is enabled. Yes (if capped)
Max Documents Maximum number of documents. Size limit takes precedence. No

Validation Configuration

Enforce data integrity using MongoDB's document validation. This card is available in both Create and Edit modes.

Document Validator

Define validation rules using JSON Schema or MongoDB query expressions. The validator textarea shows real-time JSON validation status:

  • Green "Valid" badge: JSON syntax is correct
  • Red "Invalid" badge: JSON syntax errors detected
  • Gray "Optional" badge: No validator configured

Two buttons appear next to the validator textarea:

  • Edit button (pencil icon): Opens the visual JSON Schema Editor for building schemas without writing JSON manually
  • Format button (magic wand icon): Auto-formats valid JSON for readability
Validation Configuration card showing Document Validator textarea with green 'Valid' badge, edit/format buttons, and validation level/action dropdowns JSON Schema Editor modal showing the visual schema builder interface with field type selectors, required field toggles, and generated JSON preview

Validation Level

Level Behavior
strict (Default) Apply validation to all inserts and updates
moderate Apply validation to inserts and updates on existing valid documents only
off Disable validation entirely

Validation Action

Action Behavior
error (Default) Reject documents that fail validation
warn Accept invalid documents but log validation failures

Example JSON Schema

{
  "$jsonSchema": {
    "bsonType": "object",
    "required": ["email", "username", "createdAt"],
    "properties": {
      "email": {
        "bsonType": "string",
        "pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$",
        "description": "Valid email address required"
      },
      "username": {
        "bsonType": "string",
        "minLength": 3,
        "maxLength": 50
      },
      "role": {
        "enum": ["user", "admin", "moderator"]
      },
      "createdAt": {
        "bsonType": "date"
      }
    }
  }
}

Advanced Configuration (Create Only)

This card appears only in Create mode and contains options that cannot be changed after collection creation.

Storage Engine Options

Configure WiredTiger storage engine settings. Click the gear icon to open the Storage Engine Configuration modal.

{"wiredTiger": {"configString": "block_compressor=zlib"}}

Index Option Defaults

Set default options applied to all indexes created on this collection. Click the list icon to open the configuration modal.

{"storageEngine": {"wiredTiger": {"configString": "block_compressor=zlib"}}}

Collation

Configure language-specific string comparison rules. Click the globe icon to open the Collation Configuration modal.

Option Description
locale Language locale (e.g., en_US, fr, de, zh)
strength Comparison level (1-5, affects case/accent sensitivity)
caseLevel Include case in comparison at level 1-2
numericOrdering Compare numeric strings as numbers

Write Concern

Configure acknowledgment behavior for the collection creation operation. Click the pen icon to open the Write Concern Configuration modal.

{"w": "majority", "j": true, "wtimeout": 5000}

Views & Time Series (Create Only)

This card enables creation of MongoDB views and time series collections.

Creating Views

Views are read-only collections that display data from an aggregation pipeline on a source collection.

Field Description
View Source Collection The source collection for the view. Select from autocomplete dropdown.
Aggregation Pipeline Array of pipeline stages to transform the source data
[
  {"$match": {"status": "active"}},
  {"$project": {"name": 1, "email": 1}}
]

Time Series Collections

Specialized collections optimized for time-stamped data with automatic bucketing and compression. Click "Configure Time Series" to open the configuration modal.

Field Description Required
timeField Field containing the timestamp for each document Yes
metaField Field containing metadata constant across measurements No
granularity Time bucket size: seconds, minutes, or hours No
Time Series Configuration modal showing timeField input, metaField input, and granularity dropdown with seconds/minutes/hours options

Modifiable Options

This card contains options available in both Create and Edit modes, marked with a green "Available in Edit Mode" badge.

TTL (Time To Live)

Set automatic document expiration for time series collections. Documents are deleted after the specified number of seconds from their timestamp.

Change Stream Pre/Post Images

Enable capture of document state before and after changes for change stream consumers. Use the Enable or Disable buttons for quick configuration, or edit the JSON directly.

{"enabled": true}

Advanced Features (Create Only)

This card contains specialized MongoDB features for advanced use cases.

Clustered Index

Create a collection with documents stored in clustered index order for improved query performance on the clustered key.

{"key": {"_id": 1}, "unique": true}

Encrypted Fields (Enterprise)

Configure client-side field level encryption. This feature requires MongoDB Enterprise.

{"fields": [{"path": "ssn", "bsonType": "string", "keyId": "..."}]}

Help System

Each field includes a blue question mark icon that opens a detailed help modal with field description, expected data type, example values, and a link to official MongoDB documentation.

Form Actions

The sticky footer contains action buttons:

Button Action State
Cancel Closes the activity without saving changes Always enabled
Create Collection Creates the collection with configured options (Create mode) Enabled when form is valid
Apply Changes Applies modifications using collMod (Edit mode) Enabled when form is valid

Error Handling

The interface provides real-time validation feedback:

  • Red border: Field has validation errors
  • Green border: JSON field contains valid JSON
  • Error message: Displayed below invalid fields with specific error details
  • Disabled submit: Create/Apply button disabled until all validation passes

After submission, success or error messages appear in a modal dialog indicating the operation result.

Common Use Cases

Standard Collection - Enter only the collection name and click Create. All other options use MongoDB defaults.

Validated Collection - Configure JSON Schema validation to enforce document structure. Use the visual schema editor for complex schemas.

Logging Collection - Enable Capped Collection, set appropriate size limit, and optionally set max documents for fixed-size log storage.

IoT/Metrics Collection - Configure as Time Series with appropriate timeField, metaField for device ID, and granularity matching your data frequency.

Materialized View - Set View Source Collection and define an aggregation pipeline to create a read-only transformed view of your data.

Internationalized Collection - Configure Collation with appropriate locale for proper text sorting in your application's language.

Pro Tips

  1. Use the JSON Schema Editor: Instead of writing JSON manually, click the edit button to visually build your validation schema with the GUI tool.
  2. Test Validation First: Start with validation action "warn" to identify non-compliant documents before switching to "error" mode.
  3. Size Capped Collections Properly: Account for 10-20% overhead for indexes and metadata when calculating capped collection size.
  4. Match Index Collation: When using collection-level collation, ensure indexes use the same collation for optimal query performance.
  5. Form State Persistence: Your form values are automatically saved as you type, so you won't lose work if you accidentally close the activity.

Ready to try VisuaLeaf?

Download and start managing your MongoDB databases with ease.

Download Free Trial