Registry / database / mongodb-rest-relay

mongodb-rest-relay

JSON →
library1.12.0jsnpmunverified

Relay MongoDB queries over HTTP REST, designed for edge and serverless environments. Current stable version is 1.12.0. Package is actively maintained with semantic-release. It acts as a drop-in replacement for the MongoDB Node.js driver, proxying queries to a server endpoint running near your database. Unlike MongoDB's Atlas REST API, this uses a custom relay with fixed pricing. Supports basic CRUD operations, caching via Next.js/Vercel Data Cache, and streaming. Requires bson@6.2.0 and mongodb@6.2.0 as peer dependencies. Ships TypeScript types.

npm install mongodb-rest-relay
INSTALL
IMPORT
SIG · MONGODB-REST-RELAY
M
mongodb-rest-relay
databasejavascriptv1.12.0
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.

MongoClient
import { MongoClient } from 'mongodb-rest-relay'
const { MongoClient } = require('mongodb-rest-relay')
ESM-only; CommonJS require will fail. Use ESM imports.
ObjectId
import { ObjectId } from 'mongodb-rest-relay'
import { ObjectId } from 'mongodb'
Use the ObjectId from this package if native ObjectId fails in edge environments.
makeExpressRelay
import makeExpressRelay from 'mongodb-rest-relay/lib/server/express'
import { makeExpressRelay } from 'mongodb-rest-relay'
Default import from subpath; named export not available at top level.

Shows how to use MongoClient and ObjectId from the package to perform basic CRUD via the relay.

import { MongoClient, ObjectId } from 'mongodb-rest-relay'; // Edgeside: proxy to relay server const relayUrl = process.env.RELAY_URL ?? 'http://localhost:3000/api/mongoRelay'; const client = new MongoClient(relayUrl); async function run() { try { await client.connect(); const db = client.db('test'); const collection = db.collection('docs'); const result = await collection.insertOne({ name: 'example', createdAt: new Date() }); console.log('Inserted:', result.insertedId); const doc = await collection.findOne({ _id: result.insertedId }); console.log('Found:', doc); await client.close(); } catch (err) { console.error(err); } } run();
Debug
Known issues
gotchaOnly basic CRUD operations are supported; advanced aggregation pipelines are not implemented.
fix
Check the supported operations list; for complex aggregations, use the native MongoDB driver directly.
affects: *
breakingMONGODB_RELAY_PASSWORD must be identical on both client and server sides.
fix
Set the same password environment variable on both ends.
affects: *
deprecatedThe package uses semantic-release; minor versions may contain breaking changes.
fix
Pin version or review changelog before upgrading.
affects: >=1.0.0
gotchaThe relay server must run in a Node.js environment with mongodb driver; edge functions only act as clients.
fix
Deploy the relay server (express/next) on a serverless function or server near your database.
affects: *
deprecatedUsing mongodb ObjectId in edge environments may fail unless crypto polyfill is configured.
fix
Either set { browser: { crypto: false } } in package.json or use ObjectId from mongodb-rest-relay.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'connect')
MongoClient not instantiated correctly or relay URL missing.
fix
Ensure MongoClient is imported from 'mongodb-rest-relay' and RELAY_URL env var is set.
Error: MONGODB_RELAY_PASSWORD mismatch
Relay password on client differs from server.
fix
Set MONGODB_RELAY_PASSWORD to the same value on both client and server processes.
Module not found: Package path ./lib/server/express is not exported from package
Trying to import server-side code in edge/client bundle.
fix
Only import from 'mongodb-rest-relay/lib/server/express' on the server-side (not in edge functions).
Upgrade
Version history
1.12.0latest on npm
Audit
Dependencies
bsonrequiredRequired for BSON serialization in relay
mongodbrequiredRequired on the server side for actual MongoDB operations
Agent activity
5 hits · last 30 days
node
4
Resources
mongodb-rest-relay — npm install mongodb-rest-relay · libregistry