ToollessToolless

query

Query documents from a collection

Syntax

Terminal
toollessdb query <database> <collection> [options]

Alias: toollessdb q

Arguments

ArgumentDescription
databaseName of the database
collectionName of the collection

Options

OptionDescriptionDefault
-p, --pathPath to database directory./data
-f, --filterFilter query as JSON{}
-s, --sortSort specification as JSON-
-l, --limitLimit number of results20
-k, --skipSkip number of results0
--fieldsComma-separated fields to display-
--jsonOutput as JSON array-
--countShow only count-

Examples

Query all documents:

Terminal
toollessdb query myapp users

Query with filter:

Terminal
toollessdb query myapp users -f '{"active": true}'

Complex filter with operators:

Terminal
toollessdb query myapp users -f '{"age": {"$gte": 18}, "role": {"$in": ["admin", "moderator"]}}'

Sort results:

Terminal
toollessdb query myapp posts -s '{"createdAt": -1}' -l 10

Select specific fields:

Terminal
toollessdb query myapp users --fields name,email,role

Get count only:

Terminal
toollessdb query myapp users -f '{"active": true}' --count

Output as JSON:

Terminal
toollessdb query myapp users -f '{"role": "admin"}' --json

Pagination:

Terminal
# First page
toollessdb query myapp users -l 20 -k 0

# Second page
toollessdb query myapp users -l 20 -k 20

Filter values must be valid JSON. Use single quotes around the JSON and double quotes inside.

On this page