CLI Reference

Complete command reference for the Nexa CLI - an interactive terminal for NexaDB.

MySQL-Like Interactive Terminal

The Nexa CLI provides a familiar, MySQL-like interface for interacting with NexaDB. Execute queries, manage collections, and explore your data interactively.

Installation

Install Nexa CLI
# macOS (Homebrew)
brew install nexadb
# The nexa CLI is included automatically

# Linux (One-line installer - includes both server and CLI)
curl -fsSL https://raw.githubusercontent.com/krishcdbry/nexadb/main/install.sh | bash

# Windows
# Download from: https://github.com/krishcdbry/nexa-cli/releases/latest

# Verify installation
nexa --help

Starting the CLI

Connect to NexaDB
# Start NexaDB server first
nexadb start

# Connect with default credentials (localhost)
nexa -u root -p
# Password: nexadb123

# Or connect to remote server
nexa --host db.example.com --port 6970 -u root -p
Connection Options
--hostNexaDB server host (default: localhost)
--portNexaDB server port (default: 6970)
-u, --usernameUsername for authentication (default: root)
-p, --passwordPrompt for password (secure input)

Command Reference

All commands available in the Nexa CLI with examples and descriptions.

Database Management

NEW in v3.0.4Multi-Database Architecture

NexaDB now supports multiple databases. Each database can have its own collections, providing better isolation and organization for your data.

databasesList all databases
nexa(default)> databases
āœ“ Found 3 database(s):
  [1] default
  [2] analytics
  [3] production

# The prompt shows your current database
nexa(default)>
use_db <name>Switch to a database
nexa(default)> use_db analytics
āœ“ Switched to database 'analytics'

nexa(analytics)> use_db production
āœ“ Switched to database 'production'

nexa(production)>

# Prompt now shows 'production' as current database
create_db <name>Create a new database
nexa(default)> create_db staging
āœ“ Database 'staging' created

nexa(default)> create_db test_env
āœ“ Database 'test_env' created

nexa(default)> databases
āœ“ Found 5 database(s):
  [1] default
  [2] analytics
  [3] production
  [4] staging
  [5] test_env
drop_db <name>Delete a database (destructive)
nexa(default)> drop_db test_env
āœ“ Database 'test_env' dropped

# Warning: This permanently deletes the database and all its collections!
# Cannot drop the database you're currently using

Collection Management

use <collection>Switch to a collection
nexa> use movies
āœ“ Switched to collection 'movies'

nexa(movies)> use orders
āœ“ Switched to collection 'orders'

nexa(orders)> 
collectionsList all collections
nexa> collections
āœ“ Found 3 collection(s):
* [1] movies
  [2] users
  [3] orders

# * indicates current collection

Document Operations

create <json>Create a document
nexa(movies)> create {"title": "The Matrix", "year": 1999, "rating": 8.7}
āœ“ Document created: doc_abc123def456
{
  "collection": "movies",
  "document_id": "doc_abc123def456",
  "message": "Document inserted"
}

# Create with nested objects
nexa(users)> create {"name": "Alice", "email": "alice@example.com", "profile": {"age": 30, "country": "US"}}
āœ“ Document created: doc_xyz789
query <json>Query documents with filters
# Query all documents
nexa(movies)> query {}
āœ“ Found 3 document(s):
[1]
{
  "_id": "doc_abc123",
  "title": "The Matrix",
  "year": 1999,
  "rating": 8.7
}

# Query with filters
nexa(movies)> query {"year": {"$gte": 2000}}
āœ“ Found 2 document(s):
[1]
{
  "_id": "doc_def456",
  "title": "Inception",
  "year": 2010,
  "rating": 8.8
}

# Query with exact match
nexa(users)> query {"name": "Alice"}
āœ“ Found 1 document(s)

# Query with multiple conditions
nexa(movies)> query {"year": {"$gte": 2000}, "rating": {"$gte": 8.5}}
update <id> <json>Update a document
nexa(movies)> update doc_abc123 {"rating": 9.0, "updated": true}
āœ“ Document updated: doc_abc123
{
  "collection": "movies",
  "document_id": "doc_abc123",
  "message": "Document updated"
}

# Update nested fields
nexa(users)> update doc_xyz789 {"profile": {"age": 31, "country": "US"}}
āœ“ Document updated: doc_xyz789
delete <id>Delete a document
nexa(movies)> delete doc_abc123
āœ“ Document deleted: doc_abc123

# Delete multiple documents (run query first, then delete each)
nexa(movies)> query {"year": {"$lt": 2000}}
# Find doc IDs, then delete one by one
nexa(movies)> delete doc_abc123
nexa(movies)> delete doc_def456
count [json]Count documents
# Count all documents
nexa(movies)> count
āœ“ Document count: 125

# Count with filter
nexa(movies)> count {"year": {"$gte": 2000}}
āœ“ Document count: 78

# Count by status
nexa(orders)> count {"status": "pending"}
āœ“ Document count: 15

Vector Search

vector_search <vector> [limit] [dimensions]Find similar vectors
# Basic vector search
nexa(embeddings)> vector_search [0.1, 0.95, 0.1, 0.8] 3 4
āœ“ Found 3 similar document(s):

[1] 98.50% match
{
  "_id": "doc_abc123",
  "text": "Machine learning algorithms",
  "embedding": [0.12, 0.94, 0.11, 0.79]
}

[2] 87.30% match
{
  "_id": "doc_def456",
  "text": "Artificial intelligence",
  "embedding": [0.15, 0.88, 0.13, 0.82]
}

# Search with different limit
nexa(embeddings)> vector_search [0.2, 0.8, 0.3, 0.7] 10 4
āœ“ Found 10 similar document(s):

# Higher dimensional vectors (768 dimensions for sentence transformers)
nexa(documents)> vector_search [0.01, 0.02, ..., 0.99] 5 768

Query Operators

Use MongoDB-style operators in your queries for powerful filtering.

Comparison Operators

$eq (Equal)

{"age": {"$eq": 30}}

$ne (Not Equal)

{"status": {"$ne": "inactive"}}

$gt (Greater Than)

{"price": {"$gt": 100}}

$gte (Greater Than or Equal)

{"age": {"$gte": 18}}

$lt (Less Than)

{"year": {"$lt": 2000}}

$lte (Less Than or Equal)

{"rating": {"$lte": 5.0}}

$in (In Array)

{"status": {"$in": ["active", "pending"]}}

$nin (Not In Array)

{"role": {"$nin": ["guest", "banned"]}}
Example Queries with Operators
# Find movies from 2000 or later with rating >= 8.0
nexa(movies)> query {"year": {"$gte": 2000}, "rating": {"$gte": 8.0}}

# Find active or pending orders
nexa(orders)> query {"status": {"$in": ["active", "pending"]}}

# Find users NOT from these countries
nexa(users)> query {"country": {"$nin": ["US", "UK", "CA"]}}

# Find products priced between $10 and $100
nexa(products)> query {"price": {"$gte": 10, "$lte": 100}}

# Find users over 18 but under 65
nexa(users)> query {"age": {"$gt": 18, "$lt": 65}}

System Commands

help

Display all available commands

nexa> help

exit / quit

Exit the CLI

nexa> exit

Tips & Tricks

šŸ“œ Command History

Use ↑ and ↓ arrow keys to navigate command history. Your history is saved between sessions.

āŒØļø Keyboard Shortcuts

Ctrl+C Cancel current command
Ctrl+D Exit CLI
Tab Auto-complete (future)

šŸ’” JSON Formatting

JSON must be valid! Use double quotes for strings, no trailing commas. The CLI will show helpful error messages if your JSON is invalid.

šŸŽÆ Current Collection

The prompt shows your current collection: nexa(movies)>Use use <collection> to switch.

Complete Example Session

Building a Movie Database
$ nexa -u root -p
Password: nexadb123

╔═══════════════════════════════════════════════════════════════════════╗
ā•‘     ā–ˆā–ˆā–ˆā•—   ā–ˆā–ˆā•—ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā•—ā–ˆā–ˆā•—  ā–ˆā–ˆā•— ā–ˆā–ˆā–ˆā–ˆā–ˆā•— ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā•— ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā•—               ā•‘
ā•‘     ā–ˆā–ˆā–ˆā–ˆā•—  ā–ˆā–ˆā•‘ā–ˆā–ˆā•”ā•ā•ā•ā•ā•ā•šā–ˆā–ˆā•—ā–ˆā–ˆā•”ā•ā–ˆā–ˆā•”ā•ā•ā–ˆā–ˆā•—ā–ˆā–ˆā•”ā•ā•ā–ˆā–ˆā•—ā–ˆā–ˆā•”ā•ā•ā–ˆā–ˆā•—              ā•‘
ā•‘     ā–ˆā–ˆā•”ā–ˆā–ˆā•— ā–ˆā–ˆā•‘ā–ˆā–ˆā–ˆā–ˆā–ˆā•—   ā•šā–ˆā–ˆā–ˆā•”ā• ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā•‘ā–ˆā–ˆā•‘  ā–ˆā–ˆā•‘ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā•”ā•              ā•‘
ā•‘     ā–ˆā–ˆā•‘ā•šā–ˆā–ˆā•—ā–ˆā–ˆā•‘ā–ˆā–ˆā•”ā•ā•ā•   ā–ˆā–ˆā•”ā–ˆā–ˆā•— ā–ˆā–ˆā•”ā•ā•ā–ˆā–ˆā•‘ā–ˆā–ˆā•‘  ā–ˆā–ˆā•‘ā–ˆā–ˆā•”ā•ā•ā–ˆā–ˆā•—              ā•‘
ā•‘     ā–ˆā–ˆā•‘ ā•šā–ˆā–ˆā–ˆā–ˆā•‘ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā•—ā–ˆā–ˆā•”ā• ā–ˆā–ˆā•—ā–ˆā–ˆā•‘  ā–ˆā–ˆā•‘ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā•”ā•ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā•”ā•              ā•‘
ā•‘     ā•šā•ā•  ā•šā•ā•ā•ā•ā•šā•ā•ā•ā•ā•ā•ā•ā•šā•ā•  ā•šā•ā•ā•šā•ā•  ā•šā•ā•ā•šā•ā•ā•ā•ā•ā• ā•šā•ā•ā•ā•ā•ā•               ā•‘
ā•‘                                                                       ā•‘
ā•‘            Database for AI Developers - v3.0.4                       ā•‘
ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•

āœ“ Connected to NexaDB v3.0.4
Multi-Database Architecture āœ“

Type 'help' for commands or 'exit' to quit.

nexa(default)> create_db entertainment
āœ“ Database 'entertainment' created

nexa(default)> use_db entertainment
āœ“ Switched to database 'entertainment'

nexa(entertainment)> use movies
āœ“ Switched to collection 'movies'

nexa(entertainment:movies)> create {"title": "The Matrix", "year": 1999, "rating": 8.7, "genre": "sci-fi"}
āœ“ Document created: doc_abc123

nexa(entertainment:movies)> create {"title": "Inception", "year": 2010, "rating": 8.8, "genre": "sci-fi"}
āœ“ Document created: doc_def456

nexa(entertainment:movies)> create {"title": "The Shawshank Redemption", "year": 1994, "rating": 9.3, "genre": "drama"}
āœ“ Document created: doc_ghi789

nexa(entertainment:movies)> query {}
āœ“ Found 3 document(s):
[1]
{
  "_id": "doc_abc123",
  "title": "The Matrix",
  "year": 1999,
  "rating": 8.7,
  "genre": "sci-fi"
}
...

nexa(entertainment:movies)> query {"year": {"$gte": 2000}}
āœ“ Found 1 document(s):
[1]
{
  "_id": "doc_def456",
  "title": "Inception",
  "year": 2010,
  "rating": 8.8,
  "genre": "sci-fi"
}

nexa(entertainment:movies)> count {"genre": "sci-fi"}
āœ“ Document count: 2

nexa(entertainment:movies)> update doc_abc123 {"rating": 8.8}
āœ“ Document updated: doc_abc123

nexa(entertainment:movies)> exit
Goodbye!