{"id":44055,"library":"ts-mongo-orm","title":"ts-mongo-orm","description":"A MongoDB ORM for Node.js and TypeScript (v0.1.0), inspired by ActiveRecord. It provides a type-safe wrapper around MongoDB with decorator-based schema validation using @hapi/joi. The library is under active development (pre-1.0.0) and may have breaking changes. Key differentiators include a separation of document and model classes, fully typed query APIs, and decorators for field validation. Peer dependencies include mongodb, @hapi/joi, and TypeScript >=4.5.5.","status":"active","version":"0.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/tylerc/ts-mongo-orm","tags":["javascript","mongo","mongodb","orm","active","record","activerecord","db","node","typescript"],"install":[{"cmd":"npm install ts-mongo-orm","lang":"bash","label":"npm"},{"cmd":"yarn add ts-mongo-orm","lang":"bash","label":"yarn"},{"cmd":"pnpm add ts-mongo-orm","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Native MongoDB driver for database operations","package":"mongodb","optional":false},{"reason":"TypeScript type definitions for mongodb","package":"@types/mongodb","optional":true},{"reason":"Schema validation for document fields","package":"@hapi/joi","optional":false},{"reason":"TypeScript type definitions for @hapi/joi","package":"@types/hapi__joi","optional":true},{"reason":"Required for decorator support and type checking","package":"typescript","optional":true}],"imports":[{"note":"ESM-only; CommonJS require works but prefer import.","wrong":"const DatabaseConnectDefault = require('ts-mongo-orm').DatabaseConnectDefault","symbol":"DatabaseConnectDefault","correct":"import { DatabaseConnectDefault } from 'ts-mongo-orm'"},{"note":"Named export, not default.","wrong":"import ActiveRecord from 'ts-mongo-orm'","symbol":"ActiveRecord","correct":"import { ActiveRecord } from 'ts-mongo-orm'"},{"note":"ObjectIdField is used for _id Field; also needs mongodb's ObjectId.","wrong":"import { Document, Field } from 'ts-mongo-orm'","symbol":"Document, Field, ObjectIdField","correct":"import { Document, Field, ObjectIdField } from 'ts-mongo-orm'"},{"note":"Requires two arguments: document class and model class. If same, pass same class twice.","wrong":"ActiveRecord.for(User)","symbol":"ActiveRecord.for","correct":"const UserAR = ActiveRecord.for(User, UserModel)"}],"quickstart":{"code":"import { DatabaseConnectDefault, ActiveRecord, Document, Field, ObjectIdField } from 'ts-mongo-orm';\nimport { ObjectId } from 'mongodb';\nimport * as Joi from '@hapi/joi';\n\n@Document\nclass User {\n  static databaseName = 'test';\n  static collectionName = 'users';\n\n  @ObjectIdField()\n  _id: ObjectId;\n\n  @Field(Joi.string().email())\n  email: string;\n\n  @Field(Joi.string().min(1))\n  name: string;\n\n  constructor() {\n    this._id = new ObjectId();\n    this.email = '';\n    this.name = '';\n  }\n}\n\nexport const UserAR = ActiveRecord.for(User, User);\n\n(async () => {\n  await DatabaseConnectDefault(process.env.MONGO_URI ?? 'mongodb://localhost:27017/test');\n  const user = await UserAR.create({ email: 'test@test.com', name: 'Test User' });\n  console.log('Created user:', user._id);\n  const found = await UserAR.findOne({ email: 'test@test.com' });\n  console.log('Found:', found?.name);\n  await UserAR.deleteOne({ _id: user._id });\n  await UserAR.close();\n})();","lang":"typescript","description":"Connects to MongoDB, defines a User document with validation, creates a record, finds it, deletes it, and closes the connection."},"warnings":[{"fix":"Pin to exact version and test upgrades carefully.","message":"API may change without notice before 1.0.0 release","severity":"breaking","affected_versions":">=0.0.0 <1.0.0"},{"fix":"Consider migrating to zod or joi v17 with built-in types.","message":"Using @types/hapi__joi is deprecated; prefer newer validation libraries","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"Always call ActiveRecord.for(DocumentClass, ModelClass) — use same class for both if no separate model.","message":"ActiveRecord.for() requires two arguments; passing one will cause runtime error","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Call await DatabaseConnectDefault(uri) at startup, before any ActiveRecord usage.","message":"DatabaseConnectDefault must be called before any database operations; otherwise queries will fail","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Add @Document decorator above the class definition.","message":"Decorator @Document must be applied to class; forgetting it will cause validation/ type errors","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'1.0.0':40 '4.5.5':72 'activ':37,77 'activerecord':15,79 'api':59 'around':23 'base':28 'break':44 'chang':45 'class':55 'db':80 'decor':27,61 'decorator-bas':26 'depend':66 'develop':38 'differenti':47 'document':52 'field':63 'fulli':56 'hapi/joi':32,69 'includ':48,67 'inspir':13 'javascript':73 'key':46 'librari':34 'may':42 'model':54 'mongo':3,74 'mongodb':6,24,68,75 'node':81 'node.js':9 'orm':4,7,76 'peer':65 'pre':39 'provid':17 'queri':58 'record':78 'safe':21 'schema':29 'separ':50 'ts':2 'ts-mongo-orm':1 'type':20,57 'type-saf':19 'typescript':11,71,82 'use':31 'v0.1.0':12 'valid':30,64 'wrapper':22","created_at":"2026-06-05T17:02:45.564248+00:00","updated_at":"2026-06-05T17:02:45.564248+00:00","problems":[{"fix":"Run 'npm install ts-mongo-orm' and ensure all peer deps are installed: npm install mongodb @hapi/joi @types/mongodb @types/hapi__joi typescript","cause":"Package not installed or missing peer dependencies","error":"Error: Cannot find module 'ts-mongo-orm'"},{"fix":"Ensure the document class has @Document decorator and both arguments to ActiveRecord.for are defined.","cause":"Forgetting to import or apply @Document decorator on the model class","error":"TypeError: Class extends value undefined is not a constructor or null"},{"fix":"Use findOne({ email: 'test@test.com' }) instead of findOne('test@test.com')","cause":"Passing a plain string to findOne instead of query object","error":"Argument of type 'string' is not assignable to parameter of type 'ObjectId | { _id: ObjectId; }'"},{"fix":"Install @hapi/joi and import: import * as Joi from '@hapi/joi'","cause":"Not importing @hapi/joi correctly or missing dependency","error":"Cannot find name 'Joi'. Did you mean 'joi'?"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/tylerc/ts-mongo-orm#readme","github":"https://github.com/tylerc/ts-mongo-orm","docs":null,"changelog":null,"pypi":null,"npm":"ts-mongo-orm","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}