Registry / database / mongodb-data-service

mongodb-data-service

JSON →
library22.39.4jsnpmunverified

MongoDB Data Service provides a high-level API on top of the MongoDB Node.js driver for MongoDB Compass. Current stable version is 22.39.4, updated regularly as part of the MongoDB Compass ecosystem. It simplifies common operations like connecting, counting, finding, sampling, and retrieving instance details with a callback-based interface. Unlike the raw driver, it adds a unified metadata model, collection/database info, and REST-like endpoints. Ships TypeScript types.

npm install mongodb-data-service
INSTALL
IMPORT
SIG · MONGODB-DATA-SERVI
M
mongodb-data-service
databasejavascriptv22.39.4
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.

connect
import { connect } from 'mongodb-data-service'
import connect from 'mongodb-data-service'
connect is a named export, not default.
DataService
import { DataService } from 'mongodb-data-service'
const DataService = require('mongodb-data-service').DataService
TypeScript type export for class instances.
ServiceInstance
import type { ServiceInstance } from 'mongodb-data-service'
const { ServiceInstance } = require('mongodb-data-service')
TypeScript type only, not runtime value.

Connects to MongoDB, counts documents, and disconnects.

import { connect } from 'mongodb-data-service'; async function main() { const service = await connect({ driverUrl: process.env.MONGO_URI ?? 'mongodb://localhost:27017' }); const count = await service.count('test.collection', {}, {}); console.log('Count:', count); await service.disconnect(); } main().catch(console.error);
Debug
Known issues
breakingv22 removed support for callback-based methods in favor of promises.
fix
Use async/await or .then() instead of callbacks.
affects: >=22.0.0
breakingv21 changed `driverUrl` option to require full mongodb:// connection string.
fix
Ensure driverUrl starts with mongodb:// or mongodb+srv://.
affects: >=21.0.0 <22.0.0
deprecatedThe `REST` endpoint 'get' method is deprecated in favor of `find` or `aggregate`.
fix
Migrate to `service.find()` with appropriate filters.
affects: >=20.0.0
gotchaCollection namespace must be in 'database.collection' format; a dot is interpreted as a separator.
fix
Use backtick string or dot notation like 'myDb.myCollection'.
affects: *
gotchaThe `connect()` function does not retry on initial connection failure; throws immediately.
fix
Wrap connect in try/catch and implement custom retry logic.
affects: *
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'collection')
Attempting to call service.collection() on an undefined service object when connect() fails silently.
fix
Ensure connect() resolves successfully before using the service. Use try/catch.
MongoServerError: Authentication failed.
Missing or incorrect credentials in driverUrl.
fix
Provide valid username:password in the connection string or use driverOptions.
TypeError: connect is not a function
Importing as default instead of named export.
fix
Use import { connect } from 'mongodb-data-service'.
Upgrade
Version history
22.39.4latest on npm
Audit
Dependencies
mongodbrequiredCore MongoDB driver for database operations
Agent activity
15 hits · last 30 days
node
14
Resources
mongodb-data-service — npm install mongodb-data-service · libregistry