Changelog
v2.10.0
The v2.10.0 version was released on June 30, 2026 (Beijing Time). This release mainly fixes automatic time field handling for incompatible field types and precision tags, and upgrades the MongoDB Go Driver to v2.7.0.
Bug Fixes
- Automatic Time Field Compatibility: Fixed the parsing and assignment logic for
mongox:"autoCreateTime"andmongox:"autoUpdateTime"on fields such astime.Time,int, andint64, preventing incompatible time values from being written to fields. - Precision Tag Handling: When a
time.Timefield incorrectly uses timestamp precision tags such as:second,:milli, or:nano, the automatic time configuration is now ignored to avoid writingUnixtimestamps intotime.Timefields. - Custom Integer Type Assignment: Automatic time fields now convert generated
Unixtimestamp values into compatible target integer types when assigning values. - Batch Field Hook Execution: Added test coverage for error propagation when executing field hooks in batches.
Dependency Updates
MongoDB Go Driver: Upgradedgo.mongodb.org/mongo-driver/v2fromv2.5.0tov2.7.0.
Related Documentation
- Document Model has been updated with the corresponding automatic time field usage notes.
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()