file-json-db
v1.6.0
Published
A resilient, zero-dependency, MongoDB-style JSON document database for Node.js
Maintainers
Readme
file-json-db
A resilient, zero-dependency, MongoDB-style JSON document database for Node.js.
Full Documentation: https://amk2406.github.io/file-json-db
GitHub: https://github.com/amk2406/file-json-db
npm: npm install file-json-db
What's new in 1.6.0
- Hybrid Update – plain objects work as
$setagain - Advanced + Fuzzy Search
upsert/upsertManyremoveDuplicates+removeUniqueDuplicatesdistinct- Richer TypeScript definitions
See the Changelog for full details.
Quick Start
npm install file-json-dbconst { JSONDB } = require('file-json-db');
const db = new JSONDB('./data');
const users = db.collection({
name: 'users',
autoId: true,
indexes: ['email', 'role']
});
// Insert
users.insert({ name: 'Ali', email: '[email protected]', role: 'dev' });
// Hybrid update (plain object = $set)
users.updateOne({ email: '[email protected]' }, { role: 'admin' });
// Or with operators
users.updateOne({ email: '[email protected]' }, { $inc: { logins: 1 } });
// Upsert
users.upsert(
{ email: '[email protected]' },
{ name: 'Sara', email: '[email protected]', role: 'tester' }
);
// Search (with fuzzy)
users.search({ keyword: 'ali', fuzzy: true })
.limit(10)
.toArray();
// Distinct values
users.distinct({ fields: ['role'] }); // ['dev', 'admin', 'tester']
// Remove duplicates
users.removeDuplicates({ field: 'email', keep: 'first' });
users.removeUniqueDuplicates(); // exact full-document duplicatesCore Concepts
- A database is a directory on disk.
- A collection is a folder inside the database.
- Documents are stored in one or more
part-XXXX.jsonfiles. - An in-memory index provides fast lookups.
- All writes are atomic.
- Zero external runtime dependencies.
Documentation
The complete guide (API reference, options, transactions, aggregation, backups, recovery, examples, etc.) lives on the documentation site:
→ https://amk2406.github.io/file-json-db
This README is intentionally short so it stays easy to scan on npm and GitHub.
License
MIT © Abdulhamid Muhammad Kabir
