Registry / database / wingbot-mongodb

wingbot-mongodb

JSON →
library4.2.13jsnpmunverified

MongoDB storage plugin for wingbot.ai chatbot framework (v4.2.13). Provides persistent storage for chat states (with optimistic locking via findOneAndUpdate), bot tokens (webview JWT), conversation logs, bot configuration, attachment cache (Facebook), audit logs with signature chain, and notification/automation records. Requires mongodb driver >=6.0.0 (peer dependency) and Node.js >=14. Ships TypeScript type definitions. The library implements a pluggable storage interface for the wingbot ecosystem; each storage class takes a `mongodb.Db` instance and optional collection name. Active maintenance with monthly releases.

npm install wingbot-mongodb
INSTALL
IMPORT
SIG · WINGBOT-MONGODB
W
wingbot-mongodb
databasejavascriptv4.2.13
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

StateStorage
import { StateStorage } from 'wingbot-mongodb'
const { StateStorage } = require('wingbot-mongodb')
ESM and CommonJS are both supported via conditional exports; the module provides named exports for all storage classes.
BotTokenStorage
import { BotTokenStorage } from 'wingbot-mongodb'
import BotTokenStorage from 'wingbot-mongodb'
Default export is not provided; all symbols are named exports.
AuditLogStorage
import { AuditLogStorage } from 'wingbot-mongodb'
TypeScript types are included; no separate @types package needed.

Creates MongoDB connection and three storage instances (state, config, chat log). Demonstrates optimistic lock, state update, config save, and chat log entry.

import { MongoClient } from 'mongodb'; import { StateStorage, BotConfigStorage, ChatLogStorage } from 'wingbot-mongodb'; const client = new MongoClient(process.env.MONGO_URI ?? 'mongodb://localhost:27017'); await client.connect(); const db = client.db('wingbot'); const stateStore = new StateStorage(db, 'states'); const configStore = new BotConfigStorage(db, 'config'); const chatLogStore = new ChatLogStorage(db, 'chatlogs'); // Save a chat state const state = await stateStore.getOrCreateAndLock('user123', 'page456', { page: '/' }); state.data.page = '/product'; await stateStore.saveState(state); // Save bot configuration await configStore.save({ pageId: 'page456', appConfig: { language: 'en' } }); // Log a chat message await chatLogStore.save({ senderId: 'user123', pageId: 'page456', text: 'Hello' }); await client.close();
Debug
Known issues
deprecatedStateStorage.addCustomIndex() is deprecated. Use MongoDB native index creation via createIndex() directly on the collection.
fix
Use db.collection('states').createIndex({ field: 1 }, options) instead.
affects: >=4.0.0
breakingNode.js >=14 required since v4.0.0; earlier versions dropped support for Node 10/12.
fix
Upgrade Node.js to version 14 or later.
affects: >=4.0.0
breakingMongoDB driver peer dependency changed from ^3.x to ^4.x in v4.0.0, causing TypeScript compilation errors if using mongodb@5.
fix
Use mongodb@^4.x. For mongodb@5+, upgrade to wingbot-mongodb@4.2.0+ which supports mongodb@5 and 6.
affects: >=4.0.0 <4.2.0
gotchaStateStorage.getOrCreateAndLock uses findOneAndUpdate with a filter that expects senderId and pageId to exist. If the document is missing, it inserts a new one but may return null if another write occurs in between (race condition).
fix
Always check the returned object; if null, retry the operation or use the id to fetch the document.
affects: >=4.0.0
gotchaThe `isCosmo` parameter in some constructors (e.g., StateStorage) changes the storage behavior for CosmosDB API; using it with regular MongoDB may cause unexpected errors.
fix
Only set `isCosmo: true` if you are using Azure Cosmos DB with MongoDB API.
affects: >=4.0.0
Errors
Common errors & fixes
Cannot find module 'mongodb' or its corresponding type declarations.
Missing mongodb peer dependency in the project.
fix
npm install mongodb
TypeError: stateStore.getOrCreateAndLock is not a function
Using an older import style or a different package version that does not export that method.
fix
Verify you are importing from 'wingbot-mongodb' and using version >=4.0.0.
MongoBulkWriteError: E11000 duplicate key error collection
Inserting a state with an already existing senderId+pageId combination when unique index is present.
fix
Use getOrCreateAndLock to safely insert or update instead of direct insert.
Upgrade
Version history
4.2.13latest on npm
Audit
Dependencies
mongodbrequiredPeer dependency; uses native MongoDB driver for all database operations.
Agent activity
25 hits · last 30 days
node
22
OpenAI (training)
1
Resources
wingbot-mongodb — npm install wingbot-mongodb · libregistry