Cosa is a simplified object modeling library for MongoDB, providing a lightweight abstraction over the MongoDB Node.js driver. The current stable version is 10.1.0, released under the MIT license, with an active maintenance status. It offers a clean, schema-based model definition API with built-in validation and query helpers, focusing on developer productivity without the overhead of a full ODM like Mongoose. The library supports ESM only, requires Node.js >=20, and is built on top of the official MongoDB driver.
npm install cosaNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates connecting to MongoDB, defining a model, creating and saving a document, and querying all documents.
Use import syntax and ensure Node.js >=20. If using CommonJS, consider transpilation or stay on v9.
Upgrade Node.js to >=20 or pin to a previous version (e.g., 9.x) if unable.
Consider using Model.create() or direct MongoDB driver operations for more explicit control.
If you need Model methods, avoid { array: true } and iterate over cursor manually.Add a unique index on the email field in MongoDB for duplicate prevention.
Replace `const m = new Model(...)` with `const m = Model.define(...)`
Change require('cosa') to import { Model } from 'cosa' and ensure Node.js >=20 or add a build step.Replace `import Model from 'cosa'` with `import { Model } from 'cosa'`Ensure you are importing { Model } and using version >=1.0.0. In ancient versions, use `Model.createModel()` instead.