Registry / database / typed-mongo

typed-mongo

JSON →
library0.0.7jsnpmunverified

typed-mongo (v0.0.7) is a minimal, strongly-typed wrapper for the MongoDB Node.js driver that provides type inference for collection operations and declarative index management. Unlike ORMs like Mongoose, it adds negligible overhead and no custom schema definitions—just TypeScript types. Released under MIT, it requires Node >=22 and peer dependency mongodb ^6.0.0. Primary differentiators: zero-cost abstractions, automatic type safety for queries and projections, and index syncing without schema definitions.

npm install typed-mongo
INSTALL
IMPORT
SIG · TYPED-MONGO
T
typed-mongo
databasejavascriptv0.0.7
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.

TypedMongo
import { TypedMongo } from 'typed-mongo'
const TypedMongo = require('typed-mongo')
ESM-only package; CommonJS require() will throw an error
TypedMongo class
import { TypedMongo } from 'typed-mongo'; const tm = new TypedMongo(db)
import TypedMongo from 'typed-mongo'
Named export only; there is no default export
Model type (for generic usage)
import { type Model } from 'typed-mongo'
TypeScript users can import Model for utility types; requires 'type' modifier

Shows how to initialize typed-mongo with a MongoDB client, define a type-safe schema, and perform basic insert and find operations.

import { MongoClient, ObjectId } from 'mongodb'; import { TypedMongo } from 'typed-mongo'; const mongoClient = new MongoClient(process.env.MONGO_URL ?? 'mongodb://localhost:27017', { ignoreUndefined: true }); await mongoClient.connect(); const db = mongoClient.db('myapp'); const typedMongo = new TypedMongo(db); type User = { _id: ObjectId; name: string; age: number; email?: string }; const UserModel = typedMongo.model<User>('users'); await UserModel.insertOne({ name: 'Alice', age: 25, email: 'alice@example.com' }); const user = await UserModel.findOne({ name: 'Alice' }); console.log(user); await mongoClient.close();
Debug
Known issues
gotchatyped-mongo requires the MongoDB client to be initialized with `ignoreUndefined: true` to avoid dropping undefined fields.
fix
Pass `{ ignoreUndefined: true }` to MongoClient constructor or ensure your documents do not contain undefined values.
affects: >=0.0.0
breakingNode.js version must be >=22.0.0. Older Node versions will not work.
fix
Upgrade Node.js to v22 or later.
affects: >=0.0.0
gotchaThe `projection` option in find() narrows the return type only by shape, not by literal keys—may not enforce exact projections.
fix
Cast result manually or await future type improvements.
affects: <=0.0.7
gotchaESM-only package; CommonJS require() will fail with ERR_REQUIRE_ESM.
fix
Use import syntax or dynamic import() in CommonJS projects.
affects: >=0.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Using require() to import an ESM-only package.
fix
Change to `import { TypedMongo } from 'typed-mongo'` or use dynamic `import('typed-mongo')`.
Type 'undefined' is not assignable to type 'number'.
Using undefined in a field that is typed as required (not optional) in the schema.
fix
Make the field optional in the type or provide a value.
Property 'nonExistentField' does not exist on type '...'.
Querying a field that is not defined in the schema type.
fix
Add the field to the schema type or remove it from the query.
The mongodb driver version must be ^6.0.0.
Installed mongodb version is incompatible.
fix
Run `npm install mongodb@^6.0.0` to satisfy peer dependency.
Upgrade
Version history
0.0.7latest on npm
Audit
Dependencies
mongodbrequiredpeer dependency; requires mongodb driver v6.x
Agent activity
17 hits · last 30 days
node
12
Meta
2
OpenAI (training)
1
Resources
typed-mongo — npm install typed-mongo · libregistry