Registry / database / mongo-strict

mongo-strict

JSON →
library0.2.2jsnpmunverified

MongoDB Smart ORM with TypeScript decorators. Current stable version 0.2.2, pre-1.0 active development. Differentiates by providing schema validation via decorators and strict typing for MongoDB documents. Lightweight alternative to Mongoose for TypeScript-first projects, but lacks maturity and documentation.

npm install mongo-strict
INSTALL
IMPORT
SIG · MONGO-STRICT
M
mongo-strict
databasejavascriptv0.2.2
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.

connect
import { connect } from 'mongo-strict'
const connect = require('mongo-strict')
ESM-only package; CommonJS require will not work.
Model
import { Model } from 'mongo-strict'
import Model from 'mongo-strict'
Named export, not default.
Schema
import { Schema } from 'mongo-strict'
Named export; used for defining schema object.

Connects to MongoDB, defines a User model with schema, creates a document, and queries it.

import { connect, Model, Schema } from 'mongo-strict'; const schema = new Schema({ name: { type: String, required: true, unique: true }, age: Number }); const User = Model('User', schema); async function run() { await connect('mongodb://localhost:27017/test'); await User.create({ name: 'Alice', age: 30 }); const users = await User.find({ age: { $gte: 25 } }); console.log(users); process.exit(0); } run().catch(err => { console.error(err); process.exit(1); });
Debug
Known issues
breakingVersion 0.2.0 changed the connect() function signature from (uri, options) to (uri, options, dbName).
fix
Update calls: connect(uri, options, dbName) where dbName is the database name string.
affects: >=0.2.0 <0.3.0
breakingModel() constructor arguments changed: previously took (name, schema, collectionName), now takes (name, schema, options).
fix
Change third argument to options object: Model('User', schema, { collection: 'myUsers' }).
affects: >=0.2.0
deprecatedThe createConnection method is deprecated in favor of connect().
fix
Replace createConnection(uri) with connect(uri).
affects: >=0.2.0
gotchaDecorators require TypeScript compiler options: experimentalDecorators and emitDecoratorMetadata must be true.
fix
Set in tsconfig.json: 'experimentalDecorators': true, 'emitDecoratorMetadata': true.
affects: all
gotchaAll operations are asynchronous; forgetting await may cause silent failures.
fix
Ensure all database operations use await or are properly handled as Promises.
affects: all
Errors
Common errors & fixes
TypeError: connect is not a function
Using default import instead of named import.
fix
Use import { connect } from 'mongo-strict'
MongoStrictError: Schema not defined for model User
Attempting to use Model before providing schema definition.
fix
Define schema with new Schema({...}) and pass to Model.
ReferenceError: require is not defined in ES module scope
Using CommonJS require in an ESM-only package.
fix
Use ES import syntax: import { ... } from 'mongo-strict'
Upgrade
Version history
0.2.2latest on npm
Audit
Dependencies
mongodbrequiredOfficial MongoDB driver for database operations.
reflect-metadatarequiredRequired for decorators to work.
Agent activity
2 hits · last 30 days
node
2
Resources
mongo-strict — npm install mongo-strict · libregistry