mongodb

mongodb connects to MongoDB, inspects collections, indexes and documents, performs focused changes, exports JSON and runs native command documents.

DatabaseVersion 1.1.4Stable
lil-terminal

Overview

Use mongodb for collections and documents with the same compact database vocabulary: hidden-password connection, indexes, previews, focused edits, JSON export, native command documents and logical backups.

Documents and collections

MongoDB stores BSON-like documents in collections rather than rows in fixed SQL tables. Documents in one collection may differ in shape, but “flexible schema” does not mean structure is irrelevant: applications still need stable field meanings, validation and indexes. Use the compact surface for common inspection and mutations, and native command documents after : when MongoDB-specific queries or operators are needed.

Syntax

lil-terminal
mongodb [options] · mongodb : <json-command>

Reference

mongodb

show the current MongoDB connection

mongodb -c <host|uri> [user] [database] [-p <port>] [-n] [-m [name]]

connect; password is requested separately when a user is supplied unless -n is used

-use <database>

select another database

-l

list databases

-t

list collections

-s <collection>

show collection indexes

-n <collection> [documents]

preview documents

-f <collection> <field> <value> [documents]

find documents by one field

-o <collection> [file] [-f]

export documents as JSON

-a <collection> : <json>

insert one document

-w <collection> <field> <value> : <json>

update matching documents

-d <collection> <field> <value>

delete matching documents

-m [name]

save the current connection in .lil.key; default name is the database

-M <name>

remove a saved connection

-k [name]

list saved connections or inspect one without showing its password

-K <name>

connect using a saved connection

-e

disconnect and clear connection data

mongodb : <json-command>

execute a native database command document

mongodb dump [file.json] [-f]

create an Extended JSON logical dump

mongodb load <file.json>

restore a lil MongoDB dump

Start with a safe inspection

Connect with mongodb -c localhost demo shop and supply the password in the separate secret prompt. You can also use mongodb:// or mongodb+srv:// without embedding credentials. Explore with -t, -n products 2 and -f products sku SHOE-1. To run a native command, pass a JSON object after :, for example mongodb : {"count":"products"}; this is not a shell for arbitrary JavaScript.

Before changing data

-w applies $set to every document matching the supplied field, and -d can remove every match. A collection export or dump contains documents, not index definitions or complete server configuration. lil uses Extended JSON for logical dumps where possible; it is not a replacement for server-side mongodump. Check permissions and backup before writes. Running the commands requires the MongoDB PHP driver and a reachable service; demonstrations are not live connections.

Inspection

-l lists databases, -t lists collections, -s lists indexes, -n previews documents and -f matches one field/value pair. -o exports a collection as JSON.

Editing

-a inserts a JSON document. -w applies $set to documents matching one field/value pair. -d deletes documents matching one field/value pair. Complex operations remain available through native command documents after :.

Dump and restore

dump stores collections as canonical Extended JSON strings when the driver supports them, preserving BSON types better than ordinary JSON. load restores lil MongoDB dumps. Use mongodump for server-wide backups that require every MongoDB feature.

Connection

-c accepts either a host or a full mongodb:// / mongodb+srv:// URI. If a separate user is supplied, the password is requested outside command history unless -n is used.

Safety

Commands run with the privileges of the supplied MongoDB credentials.

When a full MongoDB URI includes a database path and no separate database argument is supplied, that path becomes the selected database. lil dumps are data-only and do not recreate collection options or indexes; export and dump refuse collections above 100000 documents instead of writing partial data.

Saved connections

Without -m, connection data remains scoped to the current PHP session. -m [name] explicitly stores the current profile in the protected .lil.key file (0600), -K <name> reconnects from it, -k lists or inspects profiles without exposing a stored password, and -M <name> removes one. kill removes .lil.key together with the other core state. Treat the file as sensitive because an opted-in profile can contain database credentials.

Interactive sandbox preview

Run the prepared examples directly on the page. Their results are prebuilt and shown in the browser; no terminal command is executed on the server.

Inspect a MongoDB collection

Install and manage

Install the current compatible version. Choose Base for the complete feature set or Minimum for the reduced package; use upgrade to update a module that is already installed.

Base and Minimum are two packages of the same current module release, not separate command versions.

Base package

Install the complete package with local command reference and every published mode.

install mongodb
Minimum package

Install the reduced package. Local reference is omitted; help <cmd> -i opens the current server reference.

install mongodb -m
Exact public version

Install exactly this published version.

install mongodb -v 1.1.4
Check or update

Ask upgrade to check compatibility and replace the installed block only when needed.

upgrade mongodb
Remove module

Remove the extension block while leaving the core and unrelated modules intact.

install mongodb -u

Examples

Examples are copyable command lines, not actions executed by this website. Review paths, permissions and destructive flags before running them on a real project.

Inspect a MongoDB collection
mongodb
Illustrative sandbox preview — no live connection
A connection is required; the status view names the server and selected database.
Mongodb · localhost
mongodb -c localhost -n
Illustrative sandbox preview — no live connection
Connection example: server and database will be shown after a successful connection.
Mongodb · -c
mongodb -c mongodb://localhost/shop -n
Illustrative sandbox preview — no live connection
Connection example: server and database will be shown after a successful connection.
Mongodb · localhost
mongodb -c localhost demo shop
Illustrative sandbox preview — no live connection
Password is requested separately; selected database: shop.
Mongodb · localhost
mongodb -c localhost -p 27018 -n
Illustrative sandbox preview — no live connection
Connection example: server and database will be shown after a successful connection.
Select another database
mongodb -use shop
Illustrative sandbox preview — no live connection
Selected database: shop (requires an active connection)
List databases
mongodb -l
Illustrative sandbox preview — no live connection
admin
shop
List collections
mongodb -t
Illustrative sandbox preview — no live connection
products
Show collection indexes
mongodb -s products
Illustrative sandbox preview — no live connection
_id_  {"_id":1} (example of a standard index)
Preview documents
mongodb -n products 2
Illustrative sandbox preview — no live connection
{"sku": "SHOE-1", "name": "City shoe", "category": "shoes", "price": 79.9, "active": true}
{"sku": "BAG-1", "name": "Canvas bag", "category": "bags", "price": 44.5, "active": true}
Find documents by one field
mongodb -f products sku SHOE-1 2
Illustrative sandbox preview — no live connection
{"sku": "SHOE-1", "name": "City shoe", "category": "shoes", "price": 79.9, "active": true}
Export documents as JSON
mongodb -o products
Illustrative sandbox preview — no live connection
[
  {
    "sku": "SHOE-1",
    "name": "City shoe",
    "category": "shoes",
    "price": 79.9,
    "active": true
  },
  {
    "sku": "BAG-1",
    "name": "Canvas bag",
    "category": "bags",
    "price": 44.5,
    "active": true
  }
]
Export documents as JSON
mongodb -o products tmp/products-mongo.json
Illustrative sandbox preview — no live connection
Saved  sandbox/tmp/products-mongo.json (if the destination does not exist)
Mongodb · products
mongodb -o products tmp/products-mongo.json -f
Illustrative sandbox preview — no live connection
Saved  sandbox/tmp/products-mongo.json (replace existing file only with -f)
Handle a missing collection
mongodb -a products : {"sku":"NEW-1","name":"Sample","price":5}
Illustrative sandbox preview — no live connection
Inserted  1
ID  generated by server
Update matching documents
mongodb -w products sku BAG-1 : {"price":40}
Illustrative sandbox preview — no live connection
Matched  1
Updated  1 (example only)
Delete matching documents
mongodb -d products sku BAG-1
Illustrative sandbox preview — no live connection
Deleted  1 (example only; all matches would be affected)
Execute a native database command document
mongodb : {"count":"products"}
Illustrative sandbox preview — no live connection
{"n":2,"ok":1} (server response can include additional fields)
Create an Extended JSON logical dump
mongodb dump tmp/shop-mongo.json
Illustrative sandbox preview — no live connection
Saved  sandbox/tmp/shop-mongo.json
Format  lil-mongodb-json (logical data export, not server backup)
Mongodb · dump
mongodb dump tmp/shop-mongo.json -f
Illustrative sandbox preview — no live connection
Saved  sandbox/tmp/shop-mongo.json
Format  lil-mongodb-json (logical data export, not server backup)
Restore a lil MongoDB dump
mongodb load db/mongodb.json
Illustrative sandbox preview — no live connection
Restores documents from the bundled lil-mongodb-json sample; duplicate or existing records may conflict.
Save the current connection in .lil.key; default name is the database
mongodb -m shop-demo
Illustrative sandbox preview — no live connection
Saved  shop-demo (stores a sensitive profile in .lil.key)
List saved connections or inspect one without showing its password
mongodb -k
Illustrative sandbox preview — no live connection
No saved connections (unless a profile has already been saved)
List saved connections or inspect one without showing its password
mongodb -k shop-demo
Illustrative sandbox preview — no live connection
Saved connection not found: shop-demo (unless saved earlier)
Connect using a saved connection
mongodb -K unknown
Illustrative sandbox preview — no live connection
Saved connection not found: unknown
Remove a saved connection
mongodb -M unknown
Illustrative sandbox preview — no live connection
Saved connection not found: unknown
Disconnect and clear connection data
mongodb -e
Illustrative sandbox preview — no live connection
+
Mongodb · localhost
mongodb -c localhost -p 99999 -n
Illustrative sandbox preview — no live connection
Invalid database port
Mongodb · -c
mongodb -c mongodb://user:password@localhost/shop -n
Illustrative sandbox preview — no live connection
Credentials must be entered separately

File used in this example: sandbox/db/mongodb.json

The example uses a file or directory from the protected /sandbox/ documentation workspace.

{
  "format": "lil-mongodb-json",
  "version": 1,
  "database": "shop",
  "created": "2026-08-09T00:00:00+00:00",
  "collections": {
    "products": [
      "{\"sku\":\"SHOE-1\",\"name\":\"City shoe\",\"category\":\"shoes\",\"price\":79.9,\"active\":true}",
      "{\"sku\":\"BAG-1\",\"name\":\"Canvas bag\",\"category\":\"bags\",\"price\":44.5,\"active\":true}"
    ]
  }
}

Related documentation

Current public release

v1.1.42026-11-01

Production refinement

Current stable release of mongodb. mongodb connects to MongoDB, inspects collections, indexes and documents, performs focused changes, exports JSON and runs native command documents.