Skip to main content
Collection commands provide operations for managing collections within your database.

collection list

List all collections in the database with document counts.
jasonisnthappy <DATABASE> collection list

Example

jasonisnthappy mydb.db collection list

Output

Collections (3):
  • users (1,234 documents)
  • orders (5,678 documents)
  • products (432 documents)

collection create

Create a new collection. Collections are created automatically on first insert, but explicit creation can be useful for setting up schemas or indexes beforehand.
jasonisnthappy <DATABASE> collection create <NAME>

Arguments

  • name - Name of the collection to create

Example

jasonisnthappy mydb.db collection create users

Output

✓ Collection 'users' created successfully
Collection names must be unique within a database. Creating a collection that already exists will return an error.

collection drop

Permanently delete a collection and all its documents, indexes, and schemas.
jasonisnthappy <DATABASE> collection drop <NAME>

Arguments

  • name - Name of the collection to drop

Example

jasonisnthappy mydb.db collection drop temp_data

Output

✓ Collection 'temp_data' dropped successfully
  Documents deleted: 1,234
  Indexes removed: 3
This operation is irreversible. All documents in the collection will be permanently deleted.

collection info

Display detailed information about a specific collection including document count, size, indexes, and schema.
jasonisnthappy <DATABASE> collection info <NAME>

Arguments

  • name - Name of the collection to inspect

Example

jasonisnthappy mydb.db collection info users

Output

Collection: users

Statistics:
  Documents: 1,234
  Size: 456 KB
  Average Document Size: 379 bytes
  
Indexes:
  • email (unique)
  • created_at
  • age
  
Schema:
  Validation: enabled
  Required fields: name, email
  
Created: 2025-01-15 10:30:22
Modified: 2025-03-03 14:22:11

index list

List all indexes for a collection.
jasonisnthappy <DATABASE> index list <COLLECTION>

Arguments

  • collection - Name of the collection

Example

jasonisnthappy mydb.db index list users

Output

Indexes for collection 'users':
  • email (unique)
  • created_at
  • age
  • status

index create

Create an index on a field to improve query performance.
jasonisnthappy <DATABASE> index create <COLLECTION> <FIELD> [--unique]

Arguments

  • collection - Name of the collection
  • field - Field name to index (supports dot notation for nested fields)

Flags

  • --unique / -u - Make this a unique index (prevents duplicate values)

Examples

jasonisnthappy mydb.db index create users email

Output

✓ Index created on field 'email'
  Collection: users
  Unique: true
  Documents indexed: 1,234
  Duration: 45ms
Indexes dramatically improve query performance but use additional disk space. Create indexes for fields you frequently query.

index drop

Remove an index from a collection.
jasonisnthappy <DATABASE> index drop <COLLECTION> <NAME>

Arguments

  • collection - Name of the collection
  • name - Name of the index (field name)

Example

jasonisnthappy mydb.db index drop users email

Output

✓ Index 'email' dropped from collection 'users'

schema set

Set or update the JSON Schema validation for a collection.
jasonisnthappy <DATABASE> schema set <COLLECTION> <SCHEMA>

Arguments

  • collection - Name of the collection
  • schema - JSON Schema definition (as JSON string)

Example

jasonisnthappy mydb.db schema set users '{
  "type": "object",
  "required": ["name", "email"],
  "properties": {
    "name": {"type": "string"},
    "email": {"type": "string", "format": "email"},
    "age": {"type": "number", "minimum": 0}
  }
}'

Output

✓ Schema set for collection 'users'
  Required fields: name, email
  Optional fields: age
Setting a schema validates future inserts and updates but doesn’t automatically validate existing documents. Use schema validate to check existing data.

schema get

Retrieve the current schema for a collection.
jasonisnthappy <DATABASE> schema get <COLLECTION>

Arguments

  • collection - Name of the collection

Example

jasonisnthappy mydb.db schema get users

Output

{
  "type": "object",
  "required": ["name", "email"],
  "properties": {
    "name": {"type": "string"},
    "email": {"type": "string", "format": "email"},
    "age": {"type": "number", "minimum": 0}
  }
}

schema validate

Validate all existing documents in a collection against the current schema.
jasonisnthappy <DATABASE> schema validate <COLLECTION>

Arguments

  • collection - Name of the collection

Example

jasonisnthappy mydb.db schema validate users

Output

Validating collection 'users'...

✓ Valid documents: 1,230
✗ Invalid documents: 4

Invalid documents:
  ID 567: Missing required field 'email'
  ID 890: Field 'age' must be >= 0
  ID 1024: Invalid email format
  ID 1234: Field 'name' must be string
Run schema validation after setting a new schema to identify documents that need updating.

Document commands

Insert, query, and modify documents

Database commands

Database-level operations

Build docs developers (and LLMs) love