Registry / database / js-data-mongodb

js-data-mongodb

JSON →
library2.0.0jsnpmunverified

The official MongoDB adapter for JSData, a Node.js ORM. Version 2.0.0 is the current stable release, requiring js-data@3, mongodb@3+, and bson@3+. It provides a seamless integration between JSData and MongoDB, supporting all JSData CRUD operations and query features. Key differentiators include full TypeScript type definitions, adherence to JSData's adapter contract, and support for MongoDB connection URIs. The adapter follows a moderate release cadence with patch releases for bug fixes.

npm install js-data-mongodb
INSTALL
IMPORT
SIG · JS-DATA-MONGODB
J
js-data-mongodb
databasejavascriptv2.0.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.

MongoDBAdapter
import { MongoDBAdapter } from 'js-data-mongodb'
const MongoDBAdapter = require('js-data-mongodb');
ESM import is correct; CommonJS require may work but is not recommended for TypeScript projects.
MongoDBAdapter
import { MongoDBAdapter } from 'js-data-mongodb'
import MongoDBAdapter from 'js-data-mongodb'
Default import is incorrect; the adapter is a named export.
MongoDBAdapter
import { MongoDBAdapter } from 'js-data-mongodb'
import { MongoAdapter } from 'js-data-mongodb'
Wrong name; must be 'MongoDBAdapter' exactly.

Shows how to initialize the MongoDB adapter, register it with JSData, define a mapper, and perform create and findAll operations.

import { MongoDBAdapter } from 'js-data-mongodb'; import { DataStore } from 'js-data'; const store = new DataStore(); const adapter = new MongoDBAdapter({ uri: process.env.MONGO_URI ?? 'mongodb://localhost:27017' }); store.registerAdapter('mongodb', adapter, { default: true }); interface User { id: string; name: string; email: string; } const userMapper = store.defineMapper<User>('user'); async function run() { const created = await userMapper.create({ name: 'John', email: 'john@example.com' }); console.log('Created:', created); const found = await userMapper.findAll(); console.log('All users:', found); } run().catch(console.error);
Debug
Known issues
breakingVersion 2.x requires js-data@3.x; incompatible with js-data@2.x.
fix
Upgrade js-data to 3.x and ensure all peer dependencies are met.
affects: >=2.0.0
breakingRequires mongodb driver version 3.x or higher; older mongodb versions will not work.
fix
Install mongodb@3 or higher.
affects: >=2.0.0
deprecatedThe `createRecord` method in js-data is deprecated; use `create` instead.
fix
Use `mapper.create(data)` instead of `mapper.createRecord(data)`.
affects: *
gotchaAdapter does not support transactions; MongoDB transactions require a replica set and are not implemented.
fix
Use a different adapter or implement custom transaction handling.
affects: *
Errors
Common errors & fixes
TypeError: Cannot read property 'collection' of undefined
Adapter not properly initialized or MongoDB connection failed.
fix
Ensure MongoDB URI is correct and the adapter is registered before performing operations.
MongoError: failed to connect to server [localhost:27017] on first connect
MongoDB server is not running or not accessible.
fix
Start MongoDB service or check connection URI.
Cannot find module 'bson'
Missing peer dependency bson.
fix
Run `npm install bson@3`.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
bsonrequiredRequired for BSON serialization/deserialization in MongoDB operations.
js-datarequiredPeer dependency; the ORM core that this adapter integrates with.
mongodbrequiredMongoDB driver for database connectivity.
Agent activity
5 hits · last 30 days
node
4
Google (search)
1
Resources
js-data-mongodb — npm install js-data-mongodb · libregistry