A lightweight aliasing layer on top of the MongoDB Node.js driver that translates long field names to short keys for storage optimization. Current stable version is 1.0.13, released sporadically as a single-developer project. Unlike Mongoose, mongo-alias does not override native driver commands, keeping full control of the DB object and enabling direct logging. It focuses solely on field aliasing and automatic createdAt/updatedAt timestamps, deliberately omitting schema validation, middleware, virtuals, and population. This package is suitable for developers who want minimal overhead (42KB) and fine-grained control over MongoDB queries.
npm install mongo-aliasNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates connecting to MongoDB, creating an alias manager, inserting, and querying with automatic field translation and timestamps.
Upgrade Node.js to 18+ or stay on older mongo-alias versions if needed (none exist, so upgrade Node).
Use the native collection for unsupported methods, or submit a PR. Check the docs for the list of aliased methods.
Set write concern on the MongoClient or DB level instead of per-operation.
Manually handle nested object field translation if needed, or use schema-level mapping.
Explicitly set `autoTimestamps: true` in the constructor if you rely on automatic createdAt/updatedAt.
Apply aliases in the initial query; additional cursor methods bypass translation. For complex aggregations, use the native aggregate method without aliasing.
Switch to ESM import: `import MongoAlias from 'mongo-alias'` and ensure project type is 'module' or use .mjs extension.
Use named import: `import { AliasManager } from 'mongo-alias'`.Use the native collection for aggregation or manually map fields. The `aggregate` method is not aliased in this package.
Ensure the package is installed (`npm install mongo-alias`). If using TypeScript <5, add `esModuleInterop: true` and `moduleResolution: node16` or `bundler`.
Either apply validation after alias translation (on returned documents) or configure your validation to accept both long and short keys.
No dependency data recorded yet.