@bight-ts/storage-mongoose
import { createMongooseStorageAdapter, createMongooseStorageSchemas,} from "@bight-ts/storage-mongoose";createMongooseStorageAdapter(options)
Section titled “createMongooseStorageAdapter(options)”Creates a StorageAdapter that persists Bight state using Mongoose models.
MongooseStorageAdapterOptions
Section titled “MongooseStorageAdapterOptions”| Property | Type | Required | Description |
|---|---|---|---|
connect | () => Promise<unknown> | Yes | Lazy connection function. Called before each operation. Mongoose handles pooling. |
globalConfigs | Mongoose model | Yes | Model with { key: String (unique), value: Mixed } |
guildConfigs | Mongoose model | Yes | Model with { guildId: String (unique), value: Mixed } |
createMongooseStorageSchemas()
Section titled “createMongooseStorageSchemas()”Returns pre-built Mongoose schemas for the required models:
const { globalConfigSchema, guildConfigSchema } = createMongooseStorageSchemas();
const GlobalConfig = model("GlobalConfig", globalConfigSchema);const GuildConfig = model("GuildConfig", guildConfigSchema);Both schemas include timestamps: true for createdAt / updatedAt.
Behavior
Section titled “Behavior”- Uses
findOne+findOneAndUpdatewithupsert: true. - Guild values are stored as a single document per guild with a Mixed
valuefield. - The
connectfunction is called lazily before each operation — Mongoose handles connection reuse.