Versions in this module Expand all Collapse all v0 v0.5.0 Apr 21, 2026 Changes in this version + type MergeConflictError struct + Fields []string + func (e *MergeConflictError) Error() string type UpdateOptions + MaxRetries int + func WithRetry(maxRetries int) UpdateOptions v0.4.0 Apr 21, 2026 Changes in this version + func UpdateFields(ctx context.Context, model interface{}, fields bson.M, opts ...UpdateOptions) error type UpdateOptions + Unset []string + func UnsetFields(fields ...string) UpdateOptions v0.3.0 Feb 17, 2026 Changes in this version + var ErrVersionConflict = errors.New("goodm: version conflict (document was modified by another process)") + type CollectionOptions struct + ReadConcern *readconcern.ReadConcern + ReadPreference *readpref.ReadPref + WriteConcern *writeconcern.WriteConcern + type Configurable interface + CollectionOptions func() CollectionOptions type FieldSchema + IsSlice bool + SubFields []FieldSchema type Model + Version int type Schema + CollOptions CollectionOptions v0.2.0 Feb 13, 2026 Changes in this version + const DefaultDriftSampleSize + func BatchPopulate(ctx context.Context, models interface{}, field string, results interface{}, ...) error type EnforceOptions + DriftSampleSize int v0.1.1 Feb 11, 2026 v0.1.0 Feb 11, 2026 Changes in this version + var ErrNoDatabase = errors.New("goodm: no database connection (call Connect first)") + var ErrNotFound = errors.New("goodm: document not found") + func ClearMiddleware() + func Connect(ctx context.Context, uri string, dbName string) (*mongo.Database, error) + func Create(ctx context.Context, model interface{}, opts ...CreateOptions) error + func CreateMany(ctx context.Context, models interface{}, opts ...CreateOptions) error + func DB() *mongo.Database + func Delete(ctx context.Context, model interface{}, opts ...DeleteOptions) error + func DeleteOne(ctx context.Context, filter interface{}, model interface{}, ...) error + func Enforce(ctx context.Context, db *mongo.Database, opts ...EnforceOptions) error + func Find(ctx context.Context, filter interface{}, results interface{}, ...) error + func FindCursor(ctx context.Context, filter interface{}, model interface{}, ...) (*mongo.Cursor, error) + func FindOne(ctx context.Context, filter interface{}, result interface{}, ...) error + func GenerateModel(coll DiscoveredCollection, opts GenerateOptions) ([]byte, error) + func GetAll() map[string]*Schema + func ListExistingIndexes(ctx context.Context, coll *mongo.Collection) (map[string]bool, error) + func ParseBSONTag(tag string) (name string, omitempty bool) + func Populate(ctx context.Context, model interface{}, refs Refs, opts ...PopulateOptions) error + func Register(model interface{}, collection string) error + func Update(ctx context.Context, model interface{}, opts ...UpdateOptions) error + func UpdateOne(ctx context.Context, filter interface{}, update interface{}, model interface{}, ...) error + func Use(fns ...MiddlewareFunc) + func UseFor(modelName string, fns ...MiddlewareFunc) + func WithTransaction(ctx context.Context, fn func(ctx context.Context) error, ...) error + type ActionType int + const ActionCreateIndex + const ActionDropIndex + const ActionFieldDrift + type AfterCreate interface + AfterCreate func(ctx context.Context) error + type AfterDelete interface + AfterDelete func(ctx context.Context) error + type AfterSave interface + AfterSave func(ctx context.Context) error + type BeforeCreate interface + BeforeCreate func(ctx context.Context) error + type BeforeDelete interface + BeforeDelete func(ctx context.Context) error + type BeforeSave interface + BeforeSave func(ctx context.Context) error + type BulkResult struct + DeletedCount int64 + InsertedCount int64 + MatchedCount int64 + ModifiedCount int64 + func DeleteMany(ctx context.Context, filter interface{}, model interface{}, ...) (*BulkResult, error) + func UpdateMany(ctx context.Context, filter, update interface{}, model interface{}, ...) (*BulkResult, error) + type CompoundIndex struct + Fields []string + Unique bool + func NewCompoundIndex(fields ...string) CompoundIndex + func NewUniqueCompoundIndex(fields ...string) CompoundIndex + type CreateOptions struct + DB *mongo.Database + type DeleteOptions struct + DB *mongo.Database + type DiscoverOptions struct + Collections []string + SampleSize int + type DiscoveredCollection struct + DocCount int64 + Fields []DiscoveredField + Indexes []DiscoveredIndex + Name string + func Discover(ctx context.Context, db *mongo.Database, opts DiscoverOptions) ([]DiscoveredCollection, error) + type DiscoveredField struct + BSONName string + GoType string + IsIndexed bool + IsRequired bool + IsUnique bool + type DiscoveredIndex struct + Keys []string + Name string + Unique bool + type DriftError struct + Collection string + Field string + Message string + func DetectDrift(ctx context.Context, db *mongo.Database, schema *Schema) []DriftError + func (e *DriftError) Error() string + type DriftPolicy int + const DriftFatal + const DriftIgnore + const DriftWarn + type EnforceOptions struct + DriftPolicy DriftPolicy + OnDriftWarning func(d DriftError) + type EnforcementError struct + Collection string + Message string + func (e *EnforcementError) Error() string + type FieldSchema struct + BSONName string + Default string + Enum []string + Immutable bool + Index bool + Max *int + Min *int + Name string + Ref string + Required bool + Type string + Unique bool + func ParseGoodmTag(tag string) FieldSchema + type FindOptions struct + DB *mongo.Database + Limit int64 + Skip int64 + Sort bson.D + type GenerateOptions struct + EmbedModel bool + OutputDir string + PackageName string + type Indexable interface + Indexes func() []CompoundIndex + type MiddlewareFunc func(ctx context.Context, op *OpInfo, next func(context.Context) error) error + type MigrateOptions struct + DropExtras bool + DryRun bool + type MigrationAction struct + Collection string + Description string + IndexName string + Type ActionType + type MigrationPlan struct + Actions []MigrationAction + func PlanMigration(ctx context.Context, db *mongo.Database, schemas map[string]*Schema) (MigrationPlan, error) + type MigrationResult struct + Errors []error + Executed int + Skipped int + Warnings []string + func ExecuteMigration(ctx context.Context, db *mongo.Database, plan MigrationPlan, ...) (MigrationResult, error) + func Migrate(ctx context.Context, db *mongo.Database, opts MigrateOptions) (MigrationResult, error) + type Model struct + CreatedAt time.Time + ID bson.ObjectID + UpdatedAt time.Time + type OpInfo struct + Collection string + Filter interface{} + Model interface{} + ModelName string + Operation OpType + type OpType string + const OpCreate + const OpCreateMany + const OpDelete + const OpDeleteMany + const OpFind + const OpUpdate + const OpUpdateMany + type Pipeline struct + func NewPipeline(model interface{}, opts ...PipelineOptions) *Pipeline + func (p *Pipeline) AddFields(fields interface{}) *Pipeline + func (p *Pipeline) Count(field string) *Pipeline + func (p *Pipeline) Cursor(ctx context.Context) (*mongo.Cursor, error) + func (p *Pipeline) Execute(ctx context.Context, results interface{}) error + func (p *Pipeline) Group(group interface{}) *Pipeline + func (p *Pipeline) Limit(n int64) *Pipeline + func (p *Pipeline) Lookup(from, localField, foreignField, as string) *Pipeline + func (p *Pipeline) Match(filter interface{}) *Pipeline + func (p *Pipeline) Project(projection interface{}) *Pipeline + func (p *Pipeline) Skip(n int64) *Pipeline + func (p *Pipeline) Sort(sort interface{}) *Pipeline + func (p *Pipeline) Stage(stage bson.D) *Pipeline + func (p *Pipeline) Stages() []bson.D + func (p *Pipeline) Unwind(field string) *Pipeline + type PipelineOptions struct + DB *mongo.Database + type PopulateOptions struct + DB *mongo.Database + type Refs map[string]interface + type Schema struct + Collection string + CompoundIndexes []CompoundIndex + Fields []FieldSchema + Hooks []string + ModelName string + func Get(name string) (*Schema, bool) + func (s *Schema) GetField(bsonName string) *FieldSchema + func (s *Schema) HasField(bsonName string) bool + type TransactionOptions struct + DB *mongo.Database + type UpdateOptions struct + DB *mongo.Database + type ValidationError struct + Field string + Message string + func Validate(model interface{}, schema *Schema) []ValidationError + func (e ValidationError) Error() string + type ValidationErrors []ValidationError + func (ve ValidationErrors) Error() string