Registry / database / mongodb-data-api

mongodb-data-api

JSON →
library0.4.0jsnpmunverified

A Node.js SDK for MongoDB Atlas Data API, providing a typed, promise-based client to interact with MongoDB via HTTP endpoints. Current stable version is 0.4.0, released as an early-stage package with monthly commits. Key differentiators: full TypeScript support, method chaining for cluster/database/collection selection, and native support for all Data API actions (CRUD, aggregation). Alternatives like the official MongoDB driver require direct database connection, while this SDK works over HTTP-only Data API, suitable for serverless or restricted network environments.

npm install mongodb-data-api
INSTALL
IMPORT
SIG · MONGODB-DATA-API
M
mongodb-data-api
databasejavascriptv0.4.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.

createMongoDBDataAPI
import { createMongoDBDataAPI } from 'mongodb-data-api'
const createMongoDBDataAPI = require('mongodb-data-api').createMongoDBDataAPI
ESM-only package; CommonJS require will fail unless using dynamic import.
MongoDBDataAPI
import type { MongoDBDataAPI } from 'mongodb-data-api'
import { MongoDBDataAPI } from 'mongodb-data-api'
The type is exported as a TypeScript type, not a value. Use `import type` for type-only usage.
MongoDBDataAPIOptions
import type { MongoDBDataAPIOptions } from 'mongodb-data-api'
Interface for options passed to createMongoDBDataAPI.

Initialize the client using environment variables and perform a findOne operation.

import { createMongoDBDataAPI } from 'mongodb-data-api'; const api = createMongoDBDataAPI({ apiKey: process.env.MONGODB_API_KEY ?? '', appId: process.env.MONGODB_APP_ID ?? '', }); async function run() { const result = await api.findOne({ dataSource: 'Cluster0', database: 'sample_airbnb', collection: 'listingsAndReviews', filter: { property_type: 'Apartment' }, }); console.log(result.document); } run();
Debug
Known issues
breakingVersion 0.x is pre-release; API may change without major version bump.
fix
Pin to a specific version and test upgrades carefully.
affects: >=0.0.0 <1.0.0
deprecatedThe 'region' and 'cloud' options on init are no longer needed if using urlEndpoint directly.
fix
Use 'urlEndpoint' instead of 'appId' when possible for clarity.
affects: >=0.2.0
gotchaAll action methods return raw HTTP response data; errors are thrown as generic Error with status code.
fix
Wrap calls in try/catch and check error message for HTTP status.
affects: >=0.0.0
gotchaThe $cluster, $database, $collection chaining methods are not documented in README but exist in source.
fix
Use chaining after creating API instance; see chaining example in README.
affects: >=0.4.0
gotchaTypeScript types for action parameters may be incomplete; some options may accept 'any'.
fix
Check the actual API response and add explicit type assertions if needed.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'mongodb-data-api' or its corresponding type declarations.
Package is ESM-only; TypeScript projects need "module": "ESNext" and "moduleResolution": "bundler" in tsconfig.json.
fix
Configure tsconfig.json properly or use .mjs extension for Node.js ESM.
TypeError: createMongoDBDataAPI is not a function
Using CommonJS require() on an ESM-only package.
fix
Use dynamic import: const { createMongoDBDataAPI } = await import('mongodb-data-api'); or switch to ESM.
Property 'data' does not exist on type '{ document: any } & ...'
Action methods return shaped objects (e.g., { document }) instead of raw response; TypeScript types may not match actual shape.
fix
Use the returned property directly (e.g., result.document) rather than result.data.
Expected 0-1 arguments, but got 2.
Passing both 'urlEndpoint' and 'appId' to createMongoDBDataAPI caused conflict in early versions.
fix
Provide either urlEndpoint or appId, not both; in newer versions both are allowed but urlEndpoint takes precedence.
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
mongodb-data-api — npm install mongodb-data-api · libregistry