Repository navigation
goodm 0.7.0
goodm 0.7.0 closes the MongoDB feature gaps found in a review of 0.6.1 and fixes the correctness bugs that review and the follow-up adversarial reviews surfaced. It contains breaking changes; see the end of these notes. Full detail is in the CHANGELOG.
Tested against
| MongoDB | Go |
|---|---|
| 6.0.28, 7.0.45, 8.0.34 as single-node replica sets | 1.21, 1.22, 1.23 in CI; 1.26 locally |
The full suite runs with the race detector on every combination. CI now starts each server as a replica set, so transactions and write concern behavior are exercised on every run (#10).
Indexes
- Field tags
index=-1,index=hashed,index=text,index=2dsphere,sparse, andttl=<duration|seconds>. CompoundIndexgainsSparse,Name,ExpireAfterSeconds(withTTL(time.Duration)),PartialFilter, andCollation;Fieldsentries accept-fieldandfield:text/hashed/2dspheremarkers.- Tags inside subdocuments create dotted-path indexes.
- One resolved
IndexDefinitionlist per schema drivesEnforce,Migrate, andgoodm inspect;Enforcedetects mismatches in keys, uniqueness, sparseness, TTL, partial filter, and collation, andMigrateplans rebuilds instead of parsing index names. Partial filters are normalized and compared canonically.
Query layer
FindByID,Count,Exists,Distinct,FindOneAndUpdate,FindOneAndReplace,FindOneAndDelete.- Projection, hint, collation, and batch size on finds; upsert (
Upsert()), array filters, hint, and collation onUpdateOne/UpdateMany; hint and collation on deletes. - Aggregation options (
AllowDiskUse, collation, hint, batch size) and new stages;Pipelinenow runs middleware.
Bulk
NewBulk: a builder overBulkWritewith per-operation failure reporting.SaveMany: theUpdatelifecycle for a slice of models, with per-document version filters and exact per-item outcomes (conflict, not found, duplicate key, write concern, transport), concurrent outside transactions and transaction-aware inside them.CreateManygainsUnordered;*BulkErrorreports failed items witherrors.Is/errors.Assupport and aWriteConcernError.
Errors, middleware, registry
ErrDuplicateKey/*DuplicateKeyErrorwith collection, index, and field names.- Middleware can rewrite
OpInfo.FilterandOpInfo.Pipeline;Update,UpdateFields,Delete, andSaveManyAND the rewritten filter with their own. - The registry is keyed by type (
SchemaOf,Unregister); custom_idtypes are supported;Registerrejects models the driver would store differently (no_idtag,goodm.Modelembedded withoutinline, duplicate bson names, invalid inline tags). UpdateFieldsvalidates its values, converts them to the field's Go type with an explicit whitelist of safe conversions, rejects immutable fields and unreachable paths, accepts dotted paths, and leaves the caller's map alone.
Fixed
min/maxskipped zero values and truncated floats.- Middleware could not change the filter.
- Schemas keyed by bare struct name collided across packages.
Populateignored the referenced model's collection options.- Nested
WithTransactionstarted a second session; a session without a transaction now gets one. - Compound text indexes always mismatched;
discoverlost index kinds, options, custom names, and second indexes on a field.
Breaking
GetAll()returns a sorted[]*Schema;PlanMigrationtakes[]*Schema.Get(name)returns false for an ambiguous name; useSchemaOf.FieldSchema.Min/Maxare*float64.min/maxapply to zero values and to slice and map lengths.unique/index/sparse/ttltags inside subdocuments now create real indexes.- Only exported fields are schema fields; inline flattening follows the driver's rules; managed fields are found by bson name.
CreateManyreturns*BulkError; unique violations everywhere are*DuplicateKeyError;UpdateFieldsreturnsValidationErrorsfor bad values and drops undeclared subdocument keys.Pipeline.Execute/Cursorrun middleware.- Minimum Go version is 1.21.