Registry / database / bot-database

bot-database

JSON →
library3.4.5jsnpmunverified

The `bot-database` package, currently at stable version 3.4.5, provides a data persistence layer specifically designed for bot projects. It primarily integrates with MongoDB through the Mongoose ORM, abstracting common database operations to simplify data management within bot applications. This library likely offers pre-defined schemas or convenience methods tailored for typical bot data, such as user profiles, guild configurations, and command states, differentiating it from general-purpose Mongoose wrappers. Its focus on bot development aims to reduce boilerplate and streamline database interactions for bot creators. The release cadence is not explicitly stated but the version number suggests active development.

npm install bot-database
INSTALL
IMPORT
SIG · BOT-DATABASE
B
bot-database
databasejavascriptv3.4.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DataBase
import { DataBase } from 'bot-database';
const { DataBase } = require('bot-database');
While the README shows CommonJS `require`, modern TypeScript and Node.js projects increasingly use ES Modules (ESM). For type safety and better tooling, prefer the ESM `import` syntax. The CJS `require` might still work, but ESM is recommended for new code.
IDataBaseOptions
import type { IDataBaseOptions } from 'bot-database';
This is a type import for configuring the DataBase instance, ensuring correct typings when initializing the module.
UserSchema
import { UserSchema } from 'bot-database/models';
Assuming the library exports specific Mongoose schemas (e.g., for users) from a subpath. This allows direct access to pre-defined data structures for bot-related entities.

Demonstrates connecting to MongoDB, initializing the `bot-database` module, defining a Mongoose schema, and performing basic CRUD operations (create/update and find) for a bot user.

import { DataBase } from 'bot-database'; import mongoose from 'mongoose'; // Define a simple Mongoose schema for a bot user const userSchema = new mongoose.Schema({ userId: { type: String, required: true, unique: true }, username: { type: String, required: true }, guildId: { type: String }, points: { type: Number, default: 0 }, lastSeen: { type: Date, default: Date.now }, }); const UserModel = mongoose.model('User', userSchema); async function runBotDatabase() { const mongoUri = process.env.MONGO_URI ?? 'mongodb://localhost:27017/mybotdb'; try { // Initialize the bot database module const db = new DataBase({ mongoUri: mongoUri, models: { User: UserModel } // Pass in Mongoose models if the library expects them }); await db.connect(); // Connect to MongoDB console.log('Successfully connected to MongoDB!'); // Example: Create or update a user const userId = '123456789'; const username = 'TestBotUser'; let user = await UserModel.findOneAndUpdate( { userId }, { username, $inc: { points: 1 } }, { upsert: true, new: true } ); console.log('User created/updated:', user); // Example: Find a user const foundUser = await UserModel.findOne({ userId }); console.log('Found user:', foundUser); } catch (error) { console.error('Database operation failed:', error); } finally { await mongoose.disconnect(); // Disconnect from MongoDB console.log('Disconnected from MongoDB.'); } } runBotDatabase();
Debug
Known issues
gotchaThe README's `require` import example is CommonJS. While the library ships TypeScript types, implying ESM compatibility, directly using `require` in an ES Module project (e.g., `"type": "module"` in `package.json`) will result in a runtime error.
fix
For new projects or TypeScript-enabled projects, prefer `import { DataBase } from 'bot-database';`. If forced to use CommonJS for the main application, dynamic `import()` might be an option, but it complicates asynchronous execution.
affects: >=3.0.0
breakingMongoose version compatibility is crucial. Mismatched Mongoose versions between `bot-database`'s internal dependency and your project's direct `mongoose` peer dependency can lead to unexpected errors or deprecated features.
fix
Always check the `bot-database` `package.json` for its internal Mongoose dependency range (if visible) or its documentation for recommended `mongoose` versions. Ensure your project's `mongoose` peer dependency aligns to avoid conflicts. Refer to Mongoose's official compatibility matrix.
affects: >=3.0.0
gotchaFailure to properly handle Mongoose connection and disconnection can lead to open database connections or unhandled promise rejections, especially in serverless or short-lived bot environments.
fix
Ensure `db.connect()` is awaited before any database operations and `mongoose.disconnect()` is called in a `finally` block or on application shutdown to gracefully close connections. Use proper error handling with `try...catch`.
affects: >=3.0.0
Errors
Common errors & fixes
MongooseServerSelectionError: connect ECONNREFUSED
The MongoDB server is not running or is inaccessible at the specified URI.
fix
Verify that your MongoDB instance is running and accessible from your application's environment. Check the `mongoUri` for correctness (host, port, database name).
ReferenceError: require is not defined in ES module scope
You are attempting to use CommonJS `require()` syntax within an ES Module (`.mjs` file or `"type": "module"` in `package.json`) environment.
fix
Change `const { DataBase } = require('bot-database');` to `import { DataBase } from 'bot-database';`.
TypeError: Cannot read properties of undefined (reading 'connect')
The `DataBase` instance was not properly initialized or returned `undefined`, or `new DataBase()` was called without a valid configuration object if required.
fix
Ensure `new DataBase({ /* options */ })` is correctly implemented and its return value is assigned before attempting to call methods like `connect()`. Review required configuration options for the `DataBase` constructor.
Upgrade
Version history
3.4.5latest on npm
Audit
Dependencies
mongooserequiredCore Object Data Modeling (ODM) library for MongoDB integration. Used for schema definition, validation, and interaction with the database.
node-fetchrequiredUsed internally for making HTTP requests, potentially for interacting with external APIs, bot platforms, or webhooks.
uuid4requiredUsed for generating unique identifiers (UUIDs) for database entries or internal object tracking.
Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources