Registry / database / oors-mongodb

oors-mongodb

JSON →
library4.29.0jsnpmunverified

oors-mongodb (v4.29.0) is a module for the oors framework that provides MongoDB integration via Store (thin collection wrapper) and Repository (feature-rich CRUD with validation, relations, and aggregation). It supports seeding, data migration, and built-in GraphQL CRUD akin to Prisma. It uses the official MongoDB Node.js driver (v4+) and is published on npm. Release cadence is tied to the oors monorepo, with monthly patch releases. Differentiators: JSON schema validation, relation-based $lookup joins, and out-of-the-box GraphQL schema generation.

npm install oors-mongodb
INSTALL
IMPORT
SIG · OORS-MONGODB
O
oors-mongodb
databasejavascriptv4.29.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.

Store
import { Store } from 'oors-mongodb'
import Store from 'oors-mongodb'
Store is a named export, not default. ESM-only, no CJS support.
Repository
import { Repository } from 'oors-mongodb'
const Repository = require('oors-mongodb').Repository
Package is ESM-only (type: 'module') since v4. CJS require will fail.
Seeder
import { Seeder } from 'oors-mongodb/seeder'
import { Seeder } from 'oors-mongodb'
Seeder is exported from a subpath 'oors-mongodb/seeder' since v4.20.

Connects to MongoDB, defines a Repository with JSON schema, inserts and queries a document.

import { Repository } from 'oors-mongodb'; import { MongoClient } from 'mongodb'; const client = new MongoClient(process.env.MONGO_URI ?? 'mongodb://localhost:27017'); await client.connect(); const db = client.db('test'); // Define a repository with JSON schema validation const usersRepo = new Repository({ name: 'users', db, schema: { type: 'object', properties: { name: { type: 'string' }, email: { type: 'string', format: 'email' } }, required: ['name', 'email'] } }); // Insert a document const user = await usersRepo.create({ name: 'Alice', email: 'alice@example.com' }); console.log('Created user:', user); // Find with filter const found = await usersRepo.find({ email: 'alice@example.com' }); console.log('Found:', found); await client.close();
Debug
Known issues
breakingv4 moved from CJS to ESM. require() calls will fail.
fix
Use import syntax or ensure your project is configured for ESM.
affects: >=4.0.0
breakingSubpath exports like 'oors-mongodb/seeder' were introduced in v4.20. Direct import from main package may be undefined.
fix
Import Seeder from 'oors-mongodb/seeder'.
affects: >=4.20.0
deprecatedThe 'graphql' integration is deprecated in favor of a separate plugin since v4.25.
fix
Migrate to the standalone 'oors-graphql-mongodb' package.
affects: >=4.25.0
gotchaRepository.create() does not auto-generate _id unless explicitly provided. It uses MongoDB default ObjectId generation.
fix
Ensure you handle missing _id in your application logic.
affects: *
gotchaSchema validation is only applied on repository methods (create, update), not on raw collection access via store.
fix
Use Repository for validated operations; use Store for raw MongoDB driver access.
affects: *
breakingMongoDB driver peer dependency changed from v3 to v4 in oors-mongodb v4.0.
fix
Upgrade your MongoDB driver to v4.x.
affects: >=4.0.0
Errors
Common errors & fixes
TypeError: Class extends value #<Object> is not a constructor or null
Importing a class from an ESM package using require() without proper interop.
fix
Use import syntax instead of require. If you must use require, use dynamic import or set NODE_OPTIONS='--experimental-vm-modules'.
Cannot find module 'oors-mongodb/seeder' or its corresponding type declarations.
Importing Seeder from the main package path instead of the subpath export.
fix
Change import to: import { Seeder } from 'oors-mongodb/seeder';
MongoError: (Unauthorized) not authorized on admin to execute command
MongoDB connection URI does not have proper authentication or user lacks permissions.
fix
Check the MONGO_URI and ensure the user has readWrite on the target database.
Upgrade
Version history
4.29.0latest on npm
Audit
Dependencies
mongodbrequiredOfficial MongoDB driver (peer dependency, v4.x) for database operations.
oors-graphqloptionalOptional peer for GraphQL CRUD integration.
Agent activity
4 hits · last 30 days
node
4
Resources
oors-mongodb — npm install oors-mongodb · libregistry