bumbledb
v0.10.0
Published
Embedded, file-based database with MongoDB-like API for Node.js
Downloads
24
Maintainers
Readme
BumbleDB
Embedded, file-based database with MongoDB-like API for Node.js
Getting started
import initializeDb from 'bumbledb';
const dataDirectory = process.env.DATA_DIRECTORY ?? '.data';
const db = await initializeDb(dataDirectory);
const someDocument = { id: 1, name: 'Meredith', country: 'US' };
await db.collection('users').insertOne(someDocument);
const result = await db.collection('users').find({}).toArray();
console.log(result);
Insert data
insertOne
const someDocument = { id: 1, name: 'Meredith', country: 'US' };
await db.collection('users').insertOne(someDocument);
insertMany
const someDocuments = [
{ id: 1, name: 'Meredith', country: 'US' },
{ id: 2, name: 'Monika', country: 'DE' }
];
await db.collection('users').insertMany(someDocuments);
Query data
findOne
const result = await db.collection('users').findOne({ id: 5 });
find
Get all documents
const result = await db
.collection('users')
.find({})
.toArray();
Get documents matching query
const result = await db
.collection('users')
.find({ name: 'Monika', country: 'DE' })
.toArray();
Query using nested attributes
const result = await db
.collection('users')
.find({ 'address.country': 'DE' })
.toArray();
Update data
update
const newDocument = { id: 1, name: 'users', country: 'US' };
await db.collection('users').update({ id: 1 }, newDocument);
Delete data
delete
const affected = await db.collection('users').delete({ id: 1 });