Versions in this module Expand all Collapse all v1 v1.0.0 Aug 14, 2026 Changes in this version + var ErrDuplicateKey = errors.New("goose: duplicate key") + var ErrEmptyUpdate = errors.New("goose: update document is empty") + var ErrInvalidID = errors.New("goose: invalid ObjectID") + var ErrInvalidModel = errors.New("goose: model must be a pointer to a struct") + var ErrNotConnected = errors.New("goose: not connected to MongoDB") + var ErrNotFound = errors.New("goose: document not found") + var ErrTransaction = errors.New("goose: transaction failed") + var ErrValidation = errors.New("goose: validation failed") + type AfterCreateHook interface + AfterCreate func(ctx context.Context) error + type AfterDeleteHook interface + AfterDelete func(ctx context.Context) error + type AfterFindHook interface + AfterFind func(ctx context.Context) error + type AfterSaveHook interface + AfterSave func(ctx context.Context) error + type AfterUpdateHook interface + AfterUpdate func(ctx context.Context) error + type AggregationCursor struct + func (a *AggregationCursor[T]) AddFields(fields interface{}) *AggregationCursor[T] + func (a *AggregationCursor[T]) Cursor() (*Cursor[T], error) + func (a *AggregationCursor[T]) Exec() ([]*T, error) + func (a *AggregationCursor[T]) Group(group interface{}) *AggregationCursor[T] + func (a *AggregationCursor[T]) Limit(n int64) *AggregationCursor[T] + func (a *AggregationCursor[T]) Lookup(lookup LookupStage) *AggregationCursor[T] + func (a *AggregationCursor[T]) Match(filter interface{}) *AggregationCursor[T] + func (a *AggregationCursor[T]) Project(projection interface{}) *AggregationCursor[T] + func (a *AggregationCursor[T]) Skip(n int64) *AggregationCursor[T] + func (a *AggregationCursor[T]) Sort(sort interface{}) *AggregationCursor[T] + func (a *AggregationCursor[T]) Unwind(path string) *AggregationCursor[T] + type BeforeCreateHook interface + BeforeCreate func(ctx context.Context) error + type BeforeDeleteHook interface + BeforeDelete func(ctx context.Context) error + type BeforeSaveHook interface + BeforeSave func(ctx context.Context) error + type BeforeUpdateHook interface + BeforeUpdate func(ctx context.Context) error + type Client struct + func Connect(ctx context.Context, uri string, opts ...Option) (*Client, error) + func (c *Client) Database(name string) *Database + func (c *Client) DefaultDatabase() *Database + func (c *Client) Disconnect(ctx context.Context) error + func (c *Client) MongoClient() *mongo.Client + func (c *Client) WithTransaction(ctx context.Context, fn func(sessCtx context.Context) error) error + type Cursor struct + func (c *Cursor[T]) All(ctx context.Context) ([]*T, error) + func (c *Cursor[T]) Close(ctx context.Context) error + func (c *Cursor[T]) Decode() (*T, error) + func (c *Cursor[T]) Next(ctx context.Context) bool + type Database struct + func (d *Database) MongoDatabase() *mongo.Database + type DeleteResult struct + DeletedCount int64 + type DiscriminatorConfig struct + Name string + Schema *Schema + type Document struct + CreatedAt time.Time + ID primitive.ObjectID + UpdatedAt time.Time + func (d *Document) GetID() primitive.ObjectID + func (d *Document) SetID(id primitive.ObjectID) + type FieldDef struct + Default interface{} + Enum []interface{} + ForeignField string + Immutable bool + Index bool + JustOne bool + LocalField string + Lowercase bool + Match string + Max interface{} + Min interface{} + Ref string + Required bool + Select *bool + Sparse bool + Trim bool + Type FieldType + Unique bool + Uppercase bool + Validate ValidatorFn + type FieldType int + const TypeArray + const TypeBoolean + const TypeDate + const TypeDecimal128 + const TypeFloat64 + const TypeInt32 + const TypeInt64 + const TypeMap + const TypeMixed + const TypeNumber + const TypeObjectID + const TypeString + const TypeUUID + func (ft FieldType) String() string + type HookFunc func(ctx context.Context, doc interface{}) error + type HookType string + const HookCreate + const HookDeleteOne + const HookFind + const HookFindOne + const HookRemove + const HookSave + const HookUpdateOne + const HookValidate + type IndexDef struct + ExpireAfterSeconds *int32 + Keys interface{} + Name string + Sparse bool + Unique bool + type LookupStage struct + As string + ForeignField string + From string + LocalField string + type Model struct + func NewModel[T any](db *Database, collection string, schema ...*Schema) *Model[T] + func (m *Model[T]) Aggregate(ctx context.Context, pipeline ...interface{}) *AggregationCursor[T] + func (m *Model[T]) Collection() *mongo.Collection + func (m *Model[T]) CountDocuments(ctx context.Context, filter interface{}) (int64, error) + func (m *Model[T]) Create(ctx context.Context, doc *T) (*T, error) + func (m *Model[T]) CreateIndex(ctx context.Context, index IndexDef) (string, error) + func (m *Model[T]) CreateIndexes(ctx context.Context, indexes []IndexDef) ([]string, error) + func (m *Model[T]) DeleteMany(ctx context.Context, filter interface{}) (*DeleteResult, error) + func (m *Model[T]) DeleteOne(ctx context.Context, filter interface{}) (*DeleteResult, error) + func (m *Model[T]) Distinct(ctx context.Context, field string, filter interface{}) ([]interface{}, error) + func (m *Model[T]) DropIndex(ctx context.Context, name string) error + func (m *Model[T]) Exists(ctx context.Context, filter interface{}) (bool, error) + func (m *Model[T]) Find(ctx context.Context, filter ...interface{}) *Query[T] + func (m *Model[T]) FindByID(ctx context.Context, id interface{}) *Query[T] + func (m *Model[T]) FindByIDAndDelete(ctx context.Context, id interface{}) (*T, error) + func (m *Model[T]) FindByIDAndUpdate(ctx context.Context, id, update interface{}) (*T, error) + func (m *Model[T]) FindOne(ctx context.Context, filter interface{}) *Query[T] + func (m *Model[T]) FindOneAndDelete(ctx context.Context, filter interface{}) (*T, error) + func (m *Model[T]) FindOneAndUpdate(ctx context.Context, filter, update interface{}) (*T, error) + func (m *Model[T]) InsertMany(ctx context.Context, docs []*T) ([]*T, error) + func (m *Model[T]) ReplaceOne(ctx context.Context, filter interface{}, replacement *T) (*UpdateResult, error) + func (m *Model[T]) UpdateMany(ctx context.Context, filter, update interface{}) (*UpdateResult, error) + func (m *Model[T]) UpdateOne(ctx context.Context, filter, update interface{}) (*UpdateResult, error) + type Option func(*config) + func WithDatabase(name string) Option + func WithMaxPoolSize(size uint64) Option + func WithMinPoolSize(size uint64) Option + func WithTimeout(d time.Duration) Option + type Plugin func(schema *Schema, opts interface{}) + type PopulateOption struct + Match interface{} + Model string + Path string + Populate []PopulateOption + Select []string + type Query struct + func (q *Query[T]) All() ([]*T, error) + func (q *Query[T]) Count() (int64, error) + func (q *Query[T]) Cursor() (*Cursor[T], error) + func (q *Query[T]) Exec() (*T, error) + func (q *Query[T]) Lean() *Query[T] + func (q *Query[T]) Limit(n int64) *Query[T] + func (q *Query[T]) Populate(fields ...string) *Query[T] + func (q *Query[T]) Select(fields ...string) *Query[T] + func (q *Query[T]) Skip(n int64) *Query[T] + func (q *Query[T]) Sort(field string, order int) *Query[T] + func (q *Query[T]) SortBy(sorts bson.D) *Query[T] + type Schema struct + Fields map[string]FieldDef + Indexes []IndexDef + Options SchemaOptions + Plugins []pluginEntry + PostHooks map[HookType][]HookFunc + PreHooks map[HookType][]HookFunc + Virtuals map[string]VirtualDef + func MergeSchemas(parent, child *Schema) *Schema + func NewSchema(fields map[string]FieldDef, opts ...SchemaOption) *Schema + func (s *Schema) AddIndex(index IndexDef) *Schema + func (s *Schema) AddVirtual(name string, def VirtualDef) *Schema + func (s *Schema) ApplyVirtuals(doc interface{}) map[string]interface{} + func (s *Schema) GetVirtual(name string, doc interface{}) (interface{}, bool) + func (s *Schema) Post(hook HookType, fn HookFunc) *Schema + func (s *Schema) Pre(hook HookType, fn HookFunc) *Schema + func (s *Schema) SetVirtual(name string, doc interface{}, val interface{}) bool + func (s *Schema) Use(plugin Plugin, opts ...interface{}) *Schema + type SchemaOption func(*SchemaOptions) + func WithCollection(name string) SchemaOption + func WithDiscriminatorKey(key string) SchemaOption + func WithStrict(b bool) SchemaOption + func WithTimestamps(b bool) SchemaOption + func WithVersionKey(b bool) SchemaOption + type SchemaOptions struct + Collection string + DiscriminatorKey string + Strict bool + Timestamps bool + VersionKey bool + type UpdateResult struct + MatchedCount int64 + ModifiedCount int64 + UpsertedCount int64 + UpsertedID interface{} + type ValidationError struct + Field string + Kind string + Message string + Value interface{} + func (e *ValidationError) Error() string + func (e *ValidationError) Unwrap() error + type ValidationErrors struct + Errors []ValidationError + func (e *ValidationErrors) Error() string + func (e *ValidationErrors) Unwrap() error + type ValidatorFn func(value interface{}) error + func Enum(values ...interface{}) ValidatorFn + func Match(pattern string) ValidatorFn + func Max(n float64) ValidatorFn + func MaxLength(n int) ValidatorFn + func Min(n float64) ValidatorFn + func MinLength(n int) ValidatorFn + func Required(fieldName string) ValidatorFn + type VirtualDef struct + Get func(doc interface{}) interface{} + Set func(doc interface{}, val interface{})