@trust0/ridb-mongodb
v0.0.8
Published
MongoDB storage for @trust0/ridb
Readme
Description
This package is a MongoDB wrapper for the RIDB database, providing full CRUD operations and query support for MongoDB databases.
Installation & usage (typescript)
npm install @trust0/ridb @trust0/ridb-mongodb -S Using yarn:
yarn add @trust0/ridb @trust0/ridb-mongodbUsage
The following example demonstrates how to create a database with a MongoDB storage engine and a simple schema with ID primary key as string.
import { RIDB, SchemaFieldType, Doc } from '@trust0/ridb';
import createMongoDB from '@trust0/ridb-mongodb';
const MongoDB = await createMongoDB();
const db = new RIDB(
{
dbName: "test",
schemas: {
demo: {
version: 0,
primaryKey: 'id',
type: SchemaFieldType.object,
properties: {
id: {
type: SchemaFieldType.string,
maxLength: 60
}
}
}
} as const
}
)
await db.start({
storageType: MongoDB,
password: "test",
// MongoDB-specific options
url: "mongodb://localhost:27017", // Optional: defaults to mongodb://localhost:27017
dbName: "myapp", // Optional: defaults to the RIDB dbName
mongoOptions: { // Optional: MongoDB client options
maxPoolSize: 10,
serverSelectionTimeoutMS: 5000,
}
});MongoDB Configuration
The MongoDB storage accepts the following configuration options:
url: MongoDB connection string (defaults tomongodb://localhost:27017orprocess.env.MONGODB_URL)dbName: Database name in MongoDB (defaults to the RIDB database name)mongoOptions: Additional MongoDB client options (optional)
Environment Variables
You can also configure the MongoDB connection using environment variables:
MONGODB_URL: MongoDB connection string
