Registry / database / mongodb-websockets

mongodb-websockets

JSON →
library0.0.13jsnpmunverified

A fork of the official MongoDB Node.js driver that replaces the default TCP socket transport with WebSockets, enabling MongoDB connections in browser environments and environments where traditional TCP connections are restricted. Version 0.0.13 is the current release; the package is experimental and maintained irregularly. It packages the MongoDB driver bundle via Webpack for browser use and requires pnpm for development. Differs from the official driver by patching the transport layer to use WebSocket, which introduces latency and reduced performance compared to native TCP.

npm install mongodb-websockets
INSTALL
IMPORT
SIG · MONGODB-WEBSOCKETS
M
mongodb-websockets
databasejavascriptv0.0.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.

default
import { MongoClient } from 'mongodb-websockets'
const MongoClient = require('mongodb-websockets')
Package exports same symbols as official mongodb driver except uses WebSocket transport.
MongoClient
import { MongoClient } from 'mongodb-websockets'
import MongoClient from 'mongodb-websockets'
Named export, not default export.
ObjectId
import { ObjectId } from 'mongodb-websockets'
Re-exports BSON types from the bundled driver.

Demonstrates connecting to MongoDB via WebSocket, inserting a document, and closing the client. Uses async/await and error handling.

import { MongoClient } from 'mongodb-websockets'; const uri = process.env.MONGODB_URI ?? 'mongodb://localhost:27017'; const client = new MongoClient(uri, { // WebSocket options if needed serverSelectionTimeoutMS: 5000 }); async function run() { try { await client.connect(); const db = client.db('test'); const coll = db.collection('test'); const doc = { name: 'example', date: new Date() }; const result = await coll.insertOne(doc); console.log('Inserted:', result.insertedId); await client.close(); } catch (err) { console.error('Connection failed:', err); } } run();
Debug
Known issues
breakingWebSocket transport introduces significant latency and may not support all MongoDB driver features (e.g., change streams, gridfs, or TLS).
fix
Test thoroughly with your use case; fall back to official driver if features are missing.
affects: >=0.0.0
deprecatedPackage is a fork and may not receive updates aligning with official MongoDB driver releases.
fix
Monitor official driver updates; consider using native TCP if available.
affects: >=0.0.0
gotchaRequires pnpm; npm or yarn may cause issues with the bundled webpack build.
fix
Use pnpm install (not npm or yarn).
affects: >=0.0.0
gotchaBrowser usage requires webpack bundling; cannot be used directly with script tags.
fix
Run pnpm run webpack to produce a browser bundle.
affects: >=0.0.0
gotchaEngine requirement node >=14.20.1; older versions will not work.
fix
Upgrade Node.js to 14.20.1 or later.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'mongodb-websockets'
Package not installed; typo in package name.
fix
Run pnpm install mongodb-websockets (ensure using pnpm, not npm).
TypeError: MongoClient is not a constructor
Incorrect import: used default import when named export is required.
fix
Use import { MongoClient } from 'mongodb-websockets'.
ReferenceError: WebSocket is not defined
Running in environment without WebSocket (e.g., older Node.js or no global WebSocket).
fix
Use Node.js >=18 which has global WebSocket, or install 'ws' package and polyfill.
MongoServerSelectionError: connect ECONNREFUSED
MongoDB server not running or wrong URI.
fix
Verify MONGODB_URI or default uri, ensure mongod is running.
Upgrade
Version history
0.0.13latest on npm
Audit
Dependencies
mongodbrequiredForked from the official MongoDB driver; patches its network transport.
websocketrequiredWebSocket implementation used as transport.
Agent activity
2 hits · last 30 days
node
2
Resources
mongodb-websockets — npm install mongodb-websockets · libregistry