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 }
Errors
Common errors & fixes
TypeError: Mongooat is not a constructor
Using default import instead of named import
fiximport { Mongooat } from 'mongooat'; Cannot find module 'zod' or its corresponding type declarations
Missing 'zod' dependency; Mongooat expects zod as a peer dependency
fixInstall zod: npm install zod
Property 'infer' does not exist on type 'typeof Mongooat'
Using an older version of Mongooat (<2.0.0)
fixUpdate 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
fixUse new ObjectId(id) or pass an object { _id: ObjectId } Audit
Dependencies
zodrequiredRequired for schema definition and validation
mongodbrequiredPeer dependency for MongoDB driver