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.fixUse async/await or .then() instead of callbacks.
affects: >=22.0.0
breakingv21 changed `driverUrl` option to require full mongodb:// connection string.fixEnsure 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`.fixMigrate 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.fixUse backtick string or dot notation like 'myDb.myCollection'.
affects: *
gotchaThe `connect()` function does not retry on initial connection failure; throws immediately.fixWrap 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.
fixEnsure connect() resolves successfully before using the service. Use try/catch.
MongoServerError: Authentication failed.
Missing or incorrect credentials in driverUrl.
fixProvide valid username:password in the connection string or use driverOptions.
TypeError: connect is not a function
Importing as default instead of named export.
fixUse import { connect } from 'mongodb-data-service'. Audit
Dependencies
mongodbrequiredCore MongoDB driver for database operations