Repository navigation
goodm v0.3.0
What's New
Subdocument Support
goodm now recursively parses goodm tags on nested struct fields. Validation, defaults, and schema introspection work at any nesting depth — no separate registration needed for subdocument types.
type Address struct {
Street string `bson:"street" goodm:"required"`
City string `bson:"city" goodm:"required"`
Zip string `bson:"zip" goodm:"default=00000"`
}
type Order struct {
goodm.Model `bson:",inline"`
Name string `bson:"name" goodm:"required"`
Address Address `bson:"address" goodm:"required"`
Items []OrderItem `bson:"items"`
}New Features
- Recursive validation — all
goodmtags (required,enum,min,max) are enforced on nested struct fields and slice elements - Dotted error paths — validation errors use MongoDB-style paths:
"address.street","items[0].name","shipping.address.city" - Subdocument defaults —
default=Xtags inside nested structs and slice elements are applied duringCreateandCreateMany - Schema introspection —
FieldSchema.SubFieldscontains parsed inner fields;FieldSchema.IsSliceis true for[]structfields
Per-Schema Read/Write Concern
- Configurable interface — implement
CollectionOptions()on your model to set read preference, read concern, and write concern per collection - All CRUD, bulk, and pipeline operations automatically use the configured options
Schema Defaults & Optimistic Concurrency
- default=X tag — zero-valued fields are set to their schema default during
CreateandCreateMany - __v version key — documents get a version field that increments on each
Update, enabling optimistic concurrency control withErrVersionConflict
Design Details
- Leaf types (
time.Time,bson.ObjectID,bson.Decimal128) are never recursed into - Circular references handled via seen-type tracking during parsing
- Nil pointer subdocuments are skipped (no auto-materialization)
- Marking a subdocument field as
immutablemakes the entire subdocument immutable