Registry / database / mongodb-local-data-api

mongodb-local-data-api

JSON →
library1.0.1jsnpmunverified

A lightweight HTTP server that simulates the MongoDB Atlas Data API for local development and testing. Version 1.0.1 provides parity with the official Data API endpoints (find, insert, aggregate, etc.) without requiring a cloud Atlas connection. Designed for exact endpoint simulation, not production use. Release cadence is low; maintained by a single developer. Differentiator: enables offline/local testing with a real MongoDB instance instead of mocking HTTP calls or using a remote Atlas cluster.

npm install mongodb-local-data-api
INSTALL
IMPORT
SIG · MONGODB-LOCAL-DATA
M
mongodb-local-data-api
databasejavascriptv1.0.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.

setup
import { setup } from 'mongodb-local-data-api'
const { setup } = require('mongodb-local-data-api')
CommonJS require works as the package supports both ESM and CJS, but ESM is recommended.
default
import { setup } from 'mongodb-local-data-api'
import mongoLocal from 'mongodb-local-data-api'
No default export; named import { setup } is required.
setup type
import type { SetupOptions } from 'mongodb-local-data-api'
TypeScript types available, but not exported explicitly; use module augmentation or inline types if needed.

Initializes the local Data API with programmatic setup, inserts one document into a local MongoDB, and logs the response status and body.

import { setup } from 'mongodb-local-data-api'; const url = process.env.MONGODB_URL ?? 'mongodb://localhost:27017'; const apiKey = process.env.API_KEY ?? 'my-api-key'; const database = setup({ url, retryCount: 3 }); async function run() { const action = 'insertOne'; const parameters = { dataSource: 'Cluster0', database: 'test', collection: 'items', document: { name: 'test', value: 1 } }; const { status, body } = await database(action, parameters); console.log(`Status: ${status}`, body); } run().catch(console.error);
Debug
Known issues
gotchaNot intended for production use; designed solely for local development and testing. Parities Atlas Data API endpoints but lacks security and reliability features.
fix
Use only in development or test environments. For production, use the real MongoDB Atlas Data API.
affects: >=1.0.0
breakingv1.0.0 changed the version from pre-release (pre-v1) to stable. Function signatures remained compatible, but the npm package name is unchanged.
fix
No action needed, but test your code against v1.
affects: >=1.0.0
gotchaCLI options use `key` to specify API keys. Multiple keys can be set by repeating the `--key` flag, but environment variables only support `MONGODBLOCAL_KEY` for a single key (last wins).
fix
Use multiple `--key` flags in CLI or set `MONGODBLOCAL_KEY` for a single key. For multiple keys via environment, use programmatic setup.
affects: >=1.0.0
deprecatedThe `retryCount` option defaults to `Infinity` (unlimited retries). This may cause indefinite hanging if MongoDB is unreachable.
fix
Set `retryCount` to a finite number (e.g., 3) to avoid blocking indefinitely.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'mongodb-local-data-api'
Package not installed or missing dependencies.
fix
Run `npm install mongodb-local-data-api` and ensure MongoDB driver is installed (it's a peer dependency).
TypeError: database is not a function
Failed to import `setup` correctly (e.g., default import instead of named).
fix
Use `import { setup } from 'mongodb-local-data-api'` instead of importing default.
MongoError: could not connect to server
Local MongoDB instance not running or invalid connection URL.
fix
Start MongoDB locally (e.g., `docker run -p 27017:27017 mongo`) and verify `url` or `username`/`password`/`dbPort` options.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
mongodbrequiredOfficial MongoDB driver for database operations
Agent activity
6 hits · last 30 days
node
6
Resources
mongodb-local-data-api — npm install mongodb-local-data-api · libregistry