Skip to content

@bight-ts/storage-mongoose

import {
createMongooseStorageAdapter,
createMongooseStorageSchemas,
} from "@bight-ts/storage-mongoose";

Creates a StorageAdapter that persists Bight state using Mongoose models.

PropertyTypeRequiredDescription
connect() => Promise<unknown>YesLazy connection function. Called before each operation. Mongoose handles pooling.
globalConfigsMongoose modelYesModel with { key: String (unique), value: Mixed }
guildConfigsMongoose modelYesModel with { guildId: String (unique), value: Mixed }

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.

  • Uses findOne + findOneAndUpdate with upsert: true.
  • Guild values are stored as a single document per guild with a Mixed value field.
  • The connect function is called lazily before each operation — Mongoose handles connection reuse.