Registry / database / mongooat

mongooat

JSON →
library2.2.18jsnpmunverified

Mongooat is a TypeScript utility that combines Zod schemas with MongoDB, providing model validation and type inference. Current stable version: 2.2.18. It offers a lightweight alternative to Mongoose for projects already using Zod, with features like dot-notation path extraction and type-safe queries. Release cadence is irregular; maintained actively.

npm install mongooat
INSTALL
IMPORT
SIG · MONGOOAT
M
mongooat
databasejavascriptv2.2.18
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.

Mongooat
import { Mongooat } from 'mongooat'
import Mongooat from 'mongooat'
Mongooat is a named export, not a default export.
z
import { z } from 'mongooat'
import { z } from 'zod'
Mongooat re-exports Zod for convenience; you can also use 'zod' directly.
Mongooat (type utilities)
type ModelType = Mongooat.infer<typeof MyModel>
type ModelType = Mongooat.infer<MyModel>
Pass the model type, not the instance, to infer the document type.

Shows how to connect, define a model with Zod schema, perform insert and find operations, and infer TypeScript types.

import { Mongooat, z } from 'mongooat'; const mongooat = new Mongooat(process.env.MONGO_URI ?? 'mongodb://localhost:27017'); await mongooat.useDb('mydb'); const UserModel = mongooat.Model('users', z.object({ name: z.string(), age: z.number().optional() })); // Insert a document const inserted = await UserModel.insertOne({ name: 'Alice', age: 30 }); console.log('Inserted:', inserted); // Find documents const users = await UserModel.find(); console.log('Users:', users); // Type inference type UserType = Mongooat.infer<typeof UserModel>; // UserType: { name: string; age?: number | undefined }
Debug
Known issues
gotchaMongooat.infer<typeof Model> returns the document type without the _id field by default. Use Mongooat.infer<typeof Model, { includeId: true }> to include it.
fix
Use the second generic parameter to include or exclude _id.
affects: >=2.0.0
gotchaMongooat.paths utility does not support nested Maps, Sets, or Records (e.g., Map<string, {test: string}>).
fix
Avoid using these types with paths.
affects: >=2.0.0
gotchaModel instances are not documents; you must call .toObject() or similar to get a plain object after operations.
fix
Use return values directly or call .toObject() on results.
affects: >=2.0.0
deprecateduseDb() method may change in future versions; prefer passing database name in connection string.
fix
Include the database name in the MongoDB URI (e.g., 'mongodb://localhost:27017/mydb').
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: Mongooat is not a constructor
Using default import instead of named import
fix
import { Mongooat } from 'mongooat';
Cannot find module 'zod' or its corresponding type declarations
Missing 'zod' dependency; Mongooat expects zod as a peer dependency
fix
Install zod: npm install zod
Property 'infer' does not exist on type 'typeof Mongooat'
Using an older version of Mongooat (<2.0.0)
fix
Update to the latest version: npm install mongooat@latest
Argument of type 'string' is not assignable to parameter of type 'Filter<...>'
Using plain string for _id instead of ObjectId
fix
Use new ObjectId(id) or pass an object { _id: ObjectId }
Upgrade
Version history
2.2.18latest on npm
Audit
Dependencies
zodrequiredRequired for schema definition and validation
mongodbrequiredPeer dependency for MongoDB driver
Agent activity
10 hits · last 30 days
node
8
Resources
mongooat — npm install mongooat · libregistry