Skip to content

xztyle/longo-sh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

longo-ui

A k9s-style terminal UI for MongoDB database management.

Features

  • Manage multiple MongoDB connection strings (contexts)
  • Browse databases and collections interactively
  • View documents with compressed or full JSON modes
  • Execute MongoDB queries (basic and advanced)
  • Edit documents using neovim
  • Keyboard-driven navigation with shortcuts

Installation

cd longo-ui
pip install -e .

Configuration

Add a connection context

longo config add --name local --connection "mongodb://localhost:27017"
longo config add --name prod --connection "mongodb://user:pass@host:27017/db?authSource=admin"

List contexts

longo config list

Remove a context

longo config remove --name local

Usage

Launch the UI:

longo

Keyboard Shortcuts

Global

  • ? - Show help with all shortcuts
  • q - Quit application
  • c - Switch contexts
  • d - Jump to databases view
  • r - Refresh current view

Navigation

  • enter - Select item (database, collection, or document)
  • escape - Go back one level
  • ↑/↓ - Navigate up/down
  • j/k - Navigate up/down (vim-style)

Document View

  • Space - Expand/collapse current document (JSON view mode)
  • v - Toggle between JSON and table view modes
  • V - Expand all columns with horizontal scrolling (table mode only)
  • ←/→ - Scroll columns left/right (table mode only)
  • s - Open search bar (field-specific filtering)
  • / - Open sort bar (sort by field and direction)
  • : - Open drilldown bar (nested field selection)
  • Ctrl+Q - Open query bar (MongoDB queries)
  • j - View document in popup dialog
  • e - Edit selected document in neovim
  • x - Delete selected document
  • n - Next page
  • p - Previous page

Collection View

  • i - Show collection info/stats

Query Dialog

  • ctrl+e - Execute query
  • escape - Cancel query

Navigation Flow

  1. Databases View (default)

    • Shows all databases with collection counts
    • Press enter to select a database
  2. Collections View

    • Shows collections in selected database with document counts
    • Press enter to view documents in a collection
    • Press escape to go back to databases
    • Press i to show collection stats
  3. Documents View

    • Shows documents as expandable JSON (default view)
    • Press Space to expand/collapse individual documents
    • Press v to switch to table view mode
    • Press j to view document in popup dialog
    • Press e to edit document in neovim
    • Press x to delete document
    • Press s to search/filter documents
    • Press / to sort documents
    • Press Ctrl+Q to execute custom query
    • Press n/p for next/previous page
    • Press escape to go back to collections

Query Examples

Execute MongoDB queries using the Ctrl+Q key:

Basic queries:

collection.find({})
collection.find({"status": "active"})
collection.find({"age": {"$gt": 25}})

Advanced queries:

collection.find({}).sort("name", 1)
collection.find({"status": "active"}).limit(10)
db.collection_name.aggregate([{"$group": {"_id": "$status", "count": {"$sum": 1}}}])

Note: For simple sorting, use the / key (Sort Mode) instead of writing queries.

Document Views

JSON View (default)

Shows documents as compact JSON, similar to MongoDB Compass:

  • Each document displayed as single-line JSON (truncated at 200 chars)
  • Press Space to expand/collapse individual documents
  • Expanded documents show formatted, indented JSON
  • Works perfectly with collections that have varying schemas
  • Navigate with arrow keys or j/k
  • Press Space again to collapse back to single-line

Example:

# Collapsed:
1  {"_id": "507f...", "name": "John", "email": "john@example.com", "address": {...}}

# Expanded (press Space):
1  {
     "_id": "507f...",
     "name": "John",
     "email": "john@example.com",
     "address": {
       "street": "123 Main St",
       "city": "NYC"
     }
   }

Table View (press v to switch)

Shows documents in traditional column format:

  • First 10 columns by default
  • Values truncated to 50 characters
  • Press V to expand all columns with horizontal scrolling
  • Best for collections with consistent schemas

Popup Dialog (j)

View individual document as formatted JSON in a popup dialog.

Command Bar (k9s-style)

A command bar appears at the top of the screen when activated. It has four modes:

Search Mode (s)

  • Opens command bar with 🔍 Field > prompt
  • Step 1: Enter field name to filter on
    • Supports dot notation (e.g., user.address.city)
    • Use ALL_FIELDS for global search across all fields
    • Shows field suggestions as you type
    • Press → to accept top suggestion
    • Press Enter to proceed to value entry
  • Step 2: Enter value to search for
    • Uses MongoDB queries for server-side filtering
    • Searches ALL documents in collection (not just current page)
    • Case-insensitive partial matching
    • Real-time filtering with 2-second debounce
    • Press Enter to apply filter and close command bar
  • Shows total match count in header
  • Supports pagination through filtered results
  • ESC to close and clear filter

Sort Mode (/)

  • Opens command bar with ⬍ Field > prompt
  • Step 1: Enter field name to sort by
    • Supports dot notation (e.g., user.age, metadata.createdAt)
    • Shows field suggestions as you type
    • Press → to accept top suggestion
    • Press Enter to proceed to direction entry
  • Step 2: Enter sort direction
    • Type: asc, desc, 1, or -1
    • Shows suggestions: asc | desc
    • Press → to accept top suggestion
    • Press Enter to apply sort and close command bar
  • Sorting persists across page navigation
  • ESC to close without sorting

Query Mode (Ctrl+Q)

  • Opens command bar with ⚡ prompt
  • Enter MongoDB query syntax
  • Press Enter to execute
  • Example: collection.find({"status": "active"})
  • ESC to cancel

Drill Down Mode (:)

  • Opens command bar with 🎯 prompt
  • Type nested field path (e.g., user.address.city)
  • Shows suggestions below as you type
  • Press → (right arrow) to accept top suggestion
  • Press Enter to drill into that field
  • Shows nested data as table columns
  • ESC in drilldown view clears it

The command bar appears at the top when activated, with suggestions displayed below the input.

Editing Documents

  1. Navigate to a document in the Documents view
  2. Press e to open in neovim
  3. Edit the JSON
  4. Save and quit (:wq)
  5. Document will be updated in MongoDB

Note: The _id field is preserved and cannot be modified.

Configuration File

Contexts are stored in ~/.config/longo/config.yaml:

contexts:
  local: mongodb://localhost:27017
  prod: mongodb://user:pass@host:27017/db
current_context: local

Requirements

  • Python 3.8+
  • MongoDB 3.6+
  • neovim (for document editing)

Dependencies

  • textual - Modern TUI framework
  • pymongo - MongoDB driver
  • pyyaml - Configuration management

About

Fully terminal-based utility for MongoDB database interaction.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages