Changelog
v2.2.0
The v2.2.0 version was released on February 8, 2025 (Beijing Time). This version introduces a number of significant changes, including:
New Features
- Aggregator Operator: Now supports registering
Hooks, allowing you to insert custom logic before and after aggregation operations. - Hook/Plugin Types: Added hook types for
before*andafter*actions. - mongox.model: The
mongox.modelnow includes themongox:autoIDtag for theIDfield, enabling automatic generation ofIDvalues.
Refactoring
- mongox.Client Struct: Added a
mongox.Clientstruct, which currently only createsDatabaseobjects. More features, such as transaction handling, will be added in future versions. - mongox.Database Struct: Introduced the
mongox.Databasestruct to support registering global plugins. This allows you to insert custom logic before and after database operations, enhancing the scalability and maintainability of applications. - mongox.NewCollection: Updated the signature of the
mongox.NewCollectionmethod, which now requires amongox.Databaseobject. - Model Field Hook Refactor: Moved the model field hook to the
internalpackage and refactored it to support struct tagging, automatically filling field values during document insertion and updates. This reduces redundant code and improves maintainability and readability.
Removed Features
- Global Plugin Registration: Removed the ability to register plugins globally; plugins must now be registered on the
mongox.Databaseobject. - Validation Hooks: Removed the
validationstruct validation hooks. - Plugin Initialization Function: Removed the
mongox.InitPluginfunction.
Changes to Function and Method Usage
mongox.NewCollection
go// Previously userColl := mongox.NewCollection[User](mongoColl) // Now client := mongox.NewClient(mongoClient, &mongox.Config{}) database := client.NewDatabase("db-test") userColl := mongox.NewCollection[User](database, "users")Plugin Registration and Removal
go// Previously mongox.RegisterPlugin() mongox.RemovePlugin() // Now client := mongox.NewClient(mongoClient, &mongox.Config{}) database := client.NewDatabase("db-test") database.RegisterPlugin() database.RemovePlugin()