Skip to main content
Database commands operate on the entire database file and provide maintenance, monitoring, and administrative functions.

db info

Display comprehensive database information including size, collections, and configuration.
jasonisnthappy <DATABASE> db info

Example

jasonisnthappy mydb.db db info

Output

Database Information:
  Path: mydb.db
  Size: 4.2 MB
  Collections: 5
  Page Size: 4096 bytes
  Total Pages: 1024
  MVCC Enabled: true
  WAL Mode: enabled
If you specify a database path without any command, db info is executed by default.

db backup

Create a point-in-time backup of the database. The backup is a complete copy that can be opened independently.
jasonisnthappy <DATABASE> db backup <DESTINATION>

Arguments

  • destination - Path where the backup file will be created

Example

jasonisnthappy mydb.db db backup mydb.backup.db

Output

✓ Database backed up successfully
  Source: mydb.db
  Destination: mydb.backup.db
  Size: 4.2 MB
  Duration: 124ms
Backups are performed with file locking to ensure consistency. Reads and writes can continue during backup.

db compact

Reclaim disk space by removing old MVCC versions and reorganizing the B-tree structure.
jasonisnthappy <DATABASE> db compact

Example

jasonisnthappy mydb.db db compact

Output

✓ Database compacted successfully
  Before: 8.4 MB
  After: 4.2 MB
  Reclaimed: 4.2 MB (50%)
  Duration: 342ms
Compaction can take longer on large databases. The database remains available for reads during compaction.

db collections

List all collections in the database. This is an alias for collection list.
jasonisnthappy <DATABASE> db collections

Example

jasonisnthappy mydb.db db collections

Output

Collections (5):
  • users (1,234 documents)
  • orders (5,678 documents)
  • products (432 documents)
  • logs (12,345 documents)
  • sessions (89 documents)

metrics

Display real-time database metrics including transactions, cache performance, and WAL statistics.
jasonisnthappy <DATABASE> metrics

Example

jasonisnthappy mydb.db metrics

Output

Database Metrics:

Transactions:
  Total: 1,234
  Active: 2
  Committed: 1,230
  Aborted: 4
  
Cache:
  Size: 64 MB
  Hit Rate: 94.2%
  Evictions: 1,245
  
WAL:
  Size: 2.1 MB
  Checkpoints: 45
  Last Checkpoint: 2s ago
  
Errors:
  Total: 3
  Last Error: 1h ago
Use --format json to export metrics for monitoring systems like Prometheus or Datadog.

watch

Watch for real-time changes in a collection. Displays inserts, updates, and deletes as they happen.
jasonisnthappy <DATABASE> watch <COLLECTION>

Arguments

  • collection - Name of the collection to monitor

Example

jasonisnthappy mydb.db watch users

Output

Watching collection 'users' for changes... (Press Ctrl+C to stop)

[INSERT] ID: 1234
{
  "name": "Alice",
  "email": "alice@example.com"
}

[UPDATE] ID: 567
{
  "name": "Bob Smith",
  "age": 31
}

[DELETE] ID: 890
The watch command uses change streams and will run indefinitely until interrupted with Ctrl+C.

export

Export an entire collection to a JSON file. Each document is exported with its ID.
jasonisnthappy <DATABASE> export <COLLECTION> <OUTPUT>

Arguments

  • collection - Name of the collection to export
  • output - Path to the output JSON file

Example

jasonisnthappy mydb.db export users users.json

Output

✓ Exported collection 'users'
  Documents: 1,234
  File: users.json
  Size: 245 KB
  Duration: 89ms

Exported file format

[
  {"_id":1,"name":"Alice","age":30},
  {"_id":2,"name":"Bob","age":25},
  {"_id":3,"name":"Charlie","age":35}
]

import

Import documents from a JSON file into a collection. Creates the collection if it doesn’t exist.
jasonisnthappy <DATABASE> import <COLLECTION> <INPUT>

Arguments

  • collection - Name of the destination collection
  • input - Path to the input JSON file

Example

jasonisnthappy mydb.db import users users.json

Output

✓ Imported to collection 'users'
  Documents: 1,234
  File: users.json
  Duration: 156ms
Imports use bulk operations for optimal performance. The _id field is preserved if present, otherwise new IDs are generated.

Collection commands

Manage individual collections

Interactive REPL

Explore databases interactively

Build docs developers (and LLMs) love