Skip to main content

Data and CRUD

The CLI exposes both structural commands and direct CRUD commands.

Database commands

From src/commands/db.ts, the database command group is:

  • db list
  • db create <name>
  • db drop <name>
  • db use <name>
  • db current

Example:

Database workflow
liorandb db list
liorandb db create app
liorandb db use app
liorandb db current

Important source behavior:

  • db use persists the selected database into the current profile
  • db drop prompts for confirmation unless --yes is passed
  • if you drop the profile's active database, the CLI clears that stored database field

Collection commands

From src/commands/collection.ts, the collection group is:

  • collection list
  • collection create <name>
  • collection drop <name>

You can override the active database with --db <database>.

Collection workflow
liorandb collection list
liorandb collection create users
liorandb collection drop old-users --yes

JSON input styles

CRUD commands use helpers from src/utils/input.ts and accept JSON from:

  • inline --json
  • --file <path>
  • --stdin
  • --ndjson <path> for insert-many

That makes the CLI usable both for one-off commands and scripted pipelines.

Insert commands

Insert commands
liorandb insert-one users --json "{\"name\":\"Ada\",\"active\":true}"
liorandb insert-many users --file ./users.json
liorandb insert-many users --ndjson ./users.ndjson

Representative output:

Insert output
{
"database": "default",
"collection": "users",
"inserted_id": "01K2EXAMPLE"
}

Find commands

The source supports:

  • find <collection>
  • find-one <collection>

Shared query flags:

  • --db <database>
  • --filter <json>
  • --filter-file <path>
  • --stdin
  • --limit <number>
  • --skip <number>
  • --sort <json>
  • --projection <json>

Example:

Find commands
liorandb find users --filter "{\"active\":true}" --sort "{\"name\":1}" --limit 20
liorandb find-one users --filter "{\"email\":\"ada@example.com\"}"

Behavior worth knowing:

  • find streams one record per line when output mode is ndjson
  • in table mode, find materializes records and prints them as rows
  • find-one prints "No document matched." in human mode when nothing is found

Update commands

The source registers:

  • update-one <collection>
  • update-many <collection>

Extra update flags:

  • --update <json>
  • --update-file <path>
  • --upsert
Update examples
liorandb update-one users --filter "{\"email\":\"ada@example.com\"}" --update "{\"$set\":{\"active\":false}}"
liorandb update-many users --filter "{\"active\":false}" --update "{\"$set\":{\"flagged\":true}}" --upsert

Representative output:

Update output
{
"database": "default",
"collection": "users",
"matched_count": 1,
"modified_count": 1,
"upserted_id": null
}

Delete commands

The CLI registers:

  • delete-one <collection>
  • delete-many <collection>

There is one especially important safety guard in the source:

  • delete-many asks for an exact collection-name confirmation when the filter matches everything, unless --yes is passed
Delete examples
liorandb delete-one users --filter "{\"email\":\"ada@example.com\"}"
liorandb delete-many users --filter "{}"
liorandb delete-many users --filter "{}" --yes

Aggregation

The aggregate command expects a JSON array pipeline:

Aggregate
liorandb aggregate users --json "[{\"$match\":{\"active\":true}},{\"$sort\":{\"name\":1}}]"

If the provided pipeline is not an array, the command throws a CLI error.

Human and machine output

These same CRUD commands can be shaped for shell automation:

Automation-friendly output
liorandb find users --filter "{\"active\":true}" --output ndjson
liorandb find users --filter "{\"active\":true}" --json
liorandb insert-one users --json "{\"name\":\"Lin\"}" --quiet