Action-based anti-ODM for MongoDB and Node.js
const connect = ;const db = await ;
From an end developer perspective, monogram behaves just like the MongoDB Node.js driver. The key difference is that monogram converts collection functions into actions under the hood. Actions are an object representation of a function call.
const Test = db;let called = 0;Test;await Test;assert;
Monogram isn't an ODM/ORM like its uncle mongoose, It's a new abstraction entirely. You can call it an AOM, "action-object mapping". Why is this abstraction better? Consider the problem of logging all database operations to the console in an ODM. In mongoose, this is hard, because there's a lot of different types of middleware. In monogram, this is trivial, because all database operations are represented in a common form, actions, and all actions go through one pipeline.
const Test = db;let called = 0;Testaction$;await Test;assert;
The purpose of monogram is to allow you to enforce best practices, not
to prescribe best practices. Beginners are best served using a tool like
mongoose, which has a lot of
baked-in best practices to prevent you from shooting yourself in the foot.
Monogram is more for advanced users who have established best practices
they want to enforce. For example, here's how you would prevent users
updateMany() without any update operators,
which would overwrite the document.
const Test = db;let called = 0;// Will catch `updateOne()`, `updateMany()`, and `findOneAndUpdate()`// actionsTest;let threw = false;try// Normally this would delete all properties on the document// other than `_id` and `overwrite`. This is expected behavior,// but you might want to disallow it. Monogram gives you a// framework to do so.await Test;catch errorthrew = true;assert;assert;