Extends Meteor's Mongo.Collection with before/after hooks for insert, update, remove, upsert, find, and findOne operations.
Meteor Collection Hooks is a Meteor package that extends Mongo.Collection with before and after hooks for database operations like insert, update, remove, upsert, find, and findOne. It allows developers to inject custom logic into data flow, enabling cross-cutting concerns such as validation, logging, and data transformation across client and server environments. The package provides fine-grained control over database interactions without modifying the underlying MongoDB driver.
Meteor developers building applications that require custom logic around database operations, such as adding automatic timestamps, enforcing data validation, or integrating with external services. It is particularly useful for teams maintaining complex Meteor applications with shared client-server codebases.
Developers choose Meteor Collection Hooks for its lightweight, non-intrusive approach to extending Meteor's core data layer, offering direct access methods to bypass hooks when needed and full compatibility with Meteor 2.16+ and 3.x, including async support. Its unique selling point is the ability to define hooks that work consistently across environments while respecting collection validators like allow/deny.
Meteor Collection Hooks
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Most hooks support async functions in Meteor 3.x, enabling modern asynchronous operations like external API calls in after.insert or after.update hooks, as demonstrated in the async examples.
Provides direct versions of collection methods (e.g., direct.insert) to bypass hooks when needed, offering flexibility for performance-critical or administrative tasks without custom logic interference.
Hooks work consistently across client and server environments, respecting collection validators like allow/deny and enabling shared logic for validation, logging, or data transformation.
Supports before and after hooks for all key Mongo.Collection operations including insert, update, remove, upsert, find, and findOne, with detailed callback parameters and options for fine-grained control.
before.find hooks cannot be async in Meteor 3 and will throw errors, while find hooks only trigger on async cursor methods, limiting integration with synchronous query patterns and complicating migration.
In before.update hooks with multi: true, the hook is called per document but the modifier remains single, preventing document-specific modifications—a noted limitation in the README that affects data customization scenarios.
after.update hooks default to fetching previous documents, which can increase database load; disabling this requires uniform configuration across all hooks via collection-wide options, adding setup complexity.