tekir
All Packages
Databasev0.1.5

@tekir/mongodb

MongoDB via Mongoose with CRUD, soft deletes, pagination, and aggregation.

Installation

$bun add @tekir/mongodb

Features

  • BaseModel with Mongoose schema auto-registration
  • CRUD operations: create, find, update, delete
  • Lifecycle hooks via decorators or static hooks property
  • Soft deletes and pagination built in
  • MongoProvider for service container integration

Quick Example

TypeScript
import { BaseModel, mongo } from '@tekir/mongodb'

class Post extends BaseModel {
  static schema = { title: String, body: String }
}

await mongo.connect('mongodb://localhost/mydb')
const post = await Post.create({ title: 'Hello', body: '...' })

Changelog

v0.1.5LatestSeptember 16, 2026
  • Published output now uses the shared Node-targeted ESM bundle pipeline with external dependencies and generated TypeScript declarations, while Bun consumers keep the native source export.
v0.1.4July 23, 2026
  • Mongoose uses the package's resolved module instance consistently, including combined and parallel test runs.
v0.1.2July 16, 2026
  • Write/delete ID paths reject operator objects and invalid identifiers before reaching Mongoose, and fillable assignment ignores inherited properties.
v0.1.1June 13, 2026
  • Query filters are now sanitized against NoSQL injection. find, findOne, count, exists, deleteMany, updateMany, distinct, paginate, and the soft-delete scopes strip operator keys (those starting with $ or containing .) at every depth, while preserving Date/ObjectId and hand-built queries.
  • Update operations are now guarded: plain field maps are wrapped in $set, and explicit operator documents keep only a safe allowlist, so $rename/$unset/$where-style operators cannot be smuggled through.
  • findById returns null for non-string, object, or invalid ObjectId ids instead of throwing a CastError, so findOrFail gives a consistent not-found result for crafted ids.
  • Connections now apply pool-size and timeout defaults and attach an error handler (errors surface as a tekir:error event instead of an unhandled rejection). Query debug logging is off unless debug: true is set, so filter values are not logged by default.
  • Found and fixed with Fable.
v0.1.0April 1, 2026
  • Initial release

Other Database packages