Skip to content

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" and mongox:"autoUpdateTime" on fields such as time.Time, int, and int64, preventing incompatible time values from being written to fields.
  • Precision Tag Handling: When a time.Time field incorrectly uses timestamp precision tags such as :second, :milli, or :nano, the automatic time configuration is now ignored to avoid writing Unix timestamps into time.Time fields.
  • Custom Integer Type Assignment: Automatic time fields now convert generated Unix timestamp 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: Upgraded go.mongodb.org/mongo-driver/v2 from v2.5.0 to v2.7.0.
  • 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* and after* actions.
  • mongox.model: The mongox.model now includes the mongox:autoID tag for the ID field, enabling automatic generation of ID values.

Refactoring

  • mongox.Client Struct: Added a mongox.Client struct, which currently only creates Database objects. More features, such as transaction handling, will be added in future versions.
  • mongox.Database Struct: Introduced the mongox.Database struct 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.NewCollection method, which now requires a mongox.Database object.
  • Model Field Hook Refactor: Moved the model field hook to the internal package 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.Database object.
  • Validation Hooks: Removed the validation struct validation hooks.
  • Plugin Initialization Function: Removed the mongox.InitPlugin function.

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()