API Reference
Complete reference for the public surface of file-json-db v1.5.0. Types are shown in TypeScript style for clarity.
JSONDB
Create or open a database at the given path (default ./database).
Methods
| Method | Returns | Description |
|---|---|---|
collection(nameOrOptions) | Collection | Get or create a collection |
createCollection(nameOrOptions) | Collection | Alias of collection |
listCollections() | string[] | Names of collections found on disk |
dropCollection(name) | boolean | Delete collection directory |
unloadCollection(name) | boolean | Remove collection from memory |
backup(backupRoot?, options?) | string | null | Snapshot all collections |
backupAsync(backupRoot?, options?) | Promise<string | null> | Async backup |
CollectionOptions
interface CollectionOptions {
name: string;
autoId?: boolean; // default false
idField?: string; // default '_id'
idType?: 'auto' | 'uuid' | 'objectid'; // default 'auto'
indexes?: string[]; // default []
pretty?: boolean; // default true
maxPartSize?: number; // default 256 * 1024
maxRecords?: number | null;
errorLevel?: 'debug' | 'ignore'; // default 'debug'
keepIdIndex?: boolean; // default false – compact ranges for auto IDs
}
Collection
Insert
Find
Search (new in 1.5.0)
interface SearchOptions {
keyword: string; // required
fields?: string[] | null; // null = all fields
exclude?: string[]; // fields to skip
caseInsensitive?: boolean; // default true
}
Simple keyword (contains) search. Returns a QueryBuilder so you can still
chain .limit(), .sort(), .project(), .toArray(), etc.
See the Search API page for full details and examples.
Update
Delete
Other
QueryBuilder
Supports inclusion ({name:1}), exclusion ({password:0}), mixed (exclusion wins),
and _id is kept by default (use _id:0 to hide). Improved in 1.5.0.
Transaction
Same mutation methods as Collection (insert, updateOne,
deleteMany, … plus their Async variants), plus:
Query operators (summary)
$eq $ne $gt $gte $lt $lte
$in $nin $exists $regex $type
$size $elemMatch $and $or $nor
See the Queries & Operators page for full explanations.
Update operators (summary)
$set $inc $push $pull $unset
See the Update Operators page for details.