@opra/mongodb
v1.28.5
Published
Opra MongoDB adapter package
Readme
@opra/mongodb
MongoDB data service adapter for the OPRA framework
🌐 Documentation · 🚀 Getting Started · 📦 Packages · 💬 Issues
MongoDB data service adapter for the OPRA framework. Connects your MongoDB collections to OPRA's operation model — pagination, filtering, sorting, and projections work out of the box.
Features
MongoService— Base service with MongoClient or database integration and transaction supportMongoCollectionService— Ready-made CRUD service for a MongoDB collectionMongoEntityService— Entity-level service for single-document operationsMongoAdapter— Utility namespace:prepareFilter(),prepareSort(),prepareProjection(),prepareKeyValues()- Automatic translation of OPRA filter DSL to MongoDB query objects
- ObjectId handling and schema-aware field projection
Installation
npm install @opra/mongodbUsage
import { MongoCollectionService } from '@opra/mongodb';
@HttpController({ path: 'users' })
export class UsersController extends MongoCollectionService<User> {
constructor(db: Db) {
super(User, db.collection('users'));
}
@HttpOperation.Entity.FindMany({ type: User })
findMany() { return super.findMany(); }
@HttpOperation.Entity.GetOne({ type: User })
@HttpOperation.PathParam('id', 'objectId')
getOne(id: ObjectId) { return super.getOne(id); }
}Node Compatibility
- node >= 20.x
License
Available under MIT license.
