Registry / messaging / wa-multi-mongodb

wa-multi-mongodb

JSON →
library3.11.1jsnpmunverified

A multi-session WhatsApp library with MongoDB session storage, built on Baileys. v3.11.1 (Jul 2024) uses MongoDB for scalable auth/session persistence, auto-loads sessions at startup, supports QR scan only once per device, and includes auto-reconnect, group chat detection, message deletion, custom browser config, proxy support, and media download. Differentiates from file-based alternatives by using MongoDB for better scalability and session management. TypeScript types included.

npm install wa-multi-mongodb
INSTALL
IMPORT
SIG · WA-MULTI-MONGODB
W
wa-multi-mongodb
messagingjavascriptv3.11.1
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.

* as whatsapp
import * as whatsapp from 'wa-multi-mongodb'
const whatsapp = require('wa-multi-mongodb')
ESM recommended; CJS require also works but may lack TypeScript inference.
startSession
import { startSession } from 'wa-multi-mongodb'
import startSession from 'wa-multi-mongodb'
This is a named export, not default.
WhatsappSession
import type { WhatsappSession } from 'wa-multi-mongodb'
import { WhatsappSession } from 'wa-multi-mongodb'
For TypeScript type imports, use 'import type' to avoid runtime value.

Initializes MongoDB connection, starts a WhatsApp session with QR code, and sends a text message.

import * as whatsapp from 'wa-multi-mongodb'; require('dotenv').config(); const MONGODB_URI = process.env.MONGODB_URI ?? ''; if (!MONGODB_URI) { console.error('Error: MONGODB_URI not found in environment variables'); process.exit(1); } async function main() { await whatsapp.setMongoURI(MONGODB_URI); // Optionally customize database/collection: // whatsapp.setMongoDBNames('custom_db', 'custom_collection'); const session = await whatsapp.startSession('mysession', { printQR: true, onQRUpdated: (qr) => console.log('Scan QR:', qr.substring(0, 50) + '...'), onConnected: () => console.log('Connected!'), sessionId: 'default', }); // Send a message await session.sendMessage('xxxxxxxxxx@s.whatsapp.net', { text: 'Hello from wa-multi-mongodb!', }); console.log('Message sent!'); } main().catch(console.error);
Debug
Known issues
deprecatedgetConnectionState() is no longer recommended; use session.events instead.
fix
Replace getConnectionState() with event listeners (session.events.on('connection.update', ...)).
affects: >=3.10.0
breakingstartSession() no longer returns a Promise<undefined> on failure; throws an error instead.
fix
Wrap startSession() in try/catch to handle connection errors properly.
affects: >=3.11.0
gotchaMongoDB URI must be set before starting sessions or an error is thrown.
fix
Always call await whatsapp.setMongoURI(uri) before any session operations.
affects: >=3.0.0
deprecatedsetMongoDBNames() is experimental and may be removed in future versions.
fix
Use the default collection names unless you have a specific reason; avoid relying on custom names.
affects: >=3.10.0
gotchaProxy support requires additional configuration; not all proxies work with Baileys WebSocket.
fix
Test proxy thoroughly; prefer HTTP/HTTPS proxies over SOCKS. Set proxy via startSession options.
affects: >=3.10.8
Errors
Common errors & fixes
MongoServerSelectionError: connect ECONNREFUSED ...
MongoDB server is not running or URI is incorrect.
fix
Check MongoDB connection string, ensure MongoDB is running, and network allows access.
TypeError: whatsapp.startSession is not a function
Incorrect import style; used default import instead of named import.
fix
Use: import * as whatsapp from 'wa-multi-mongodb' or import { startSession } from 'wa-multi-mongodb'
Error: MongoDB URI not set. Call setMongoURI() first.
Attempted to start session before setting MongoDB URI.
fix
Call await whatsapp.setMongoURI(process.env.MONGODB_URI) before any session operation.
ERR_UNKNOWN_ENCODING: Unsupported encoding "utf8"
Incorrect Baileys version or mismatch between wa-multi-mongodb and Baileys.
fix
Ensure both packages are compatible; stick to versions specified in peerDependencies.
Upgrade
Version history
3.11.1latest on npm
Audit
Dependencies
@whiskeysockets/baileysrequiredCore WhatsApp Web protocol implementation
mongodbrequiredMongoDB driver for session storage
Agent activity
23 hits · last 30 days
node
20
OpenAI (training)
1
Resources