Connect once. Use it everywhere.
Manage startup, shared access, independent stores and clean shutdown.
From another file
// users.js — called after connect has completed
const BsonLite = require('./BsonLite.cjs');
module.exports.findUsers = () => {
return BsonLite.collection('users').find({ active: true }).toArray();
};Use the same SDK file path in your application. Calling collection or ping before connect completes throws BSONLITE_NOT_STARTED. Queries are asynchronous; find returns a cursor that you can materialize with toArray.
Independent database handles
const inventory = await BsonLite.open({
name: 'inventory',
directory: './InventoryDatabase'
});
try {
await inventory.collection('products').insertOne({ sku: 'NOTE-01' });
const names = await inventory.listCollections().toArray();
} finally {
await inventory.close();
}open accepts an options object and creates a separately owned handle. It does not configure the top-level shared connection. Separate stores need separate directories; opening the same directory twice is refused. Port selection is automatic for each engine.
Shut down cleanly
process.once('SIGINT', async () => {
// First stop accepting application requests.
await BsonLite.disconnect();
});
process.once('SIGTERM', async () => {
await BsonLite.disconnect();
});disconnect and stop are aliases for the shared instance. A Database handle uses close. Await shutdown before taking a physical backup or attempting migration. The supplied starter coordinates HTTP server closure with database shutdown.
Documentation for BsonLite 0.6.0-rc.1. View SDK source · Download the validated SDK