db

package
v2.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultDatabase string
)

Functions

This section is empty.

Types

type MongoDB

type MongoDB struct {
	Database      string
	Collection    string
	Filter        map[string]any
	SortFields    []string // 排序字段
	Index         string   // 查询索引
	IncludeFields []string // 包含字段
	ExcludeFields []string // 排除字段
	CountPipeline []bson.M // AggregateByPage
	Pipeline      []bson.M // Aggregate/AggregateByPage
}

func (*MongoDB) Aggregate

func (m *MongoDB) Aggregate(ctx context.Context, result any, opts ...options.Lister[options.AggregateOptions]) error

func (*MongoDB) AggregateByPage

func (m *MongoDB) AggregateByPage(ctx context.Context, countResult, result any, opts ...options.Lister[options.AggregateOptions]) error

func (*MongoDB) CountDocuments

func (m *MongoDB) CountDocuments(ctx context.Context) (int64, error)

func (*MongoDB) DeleteMany

func (m *MongoDB) DeleteMany(ctx context.Context) (int64, error)

func (*MongoDB) DeleteOne

func (m *MongoDB) DeleteOne(ctx context.Context) (int64, error)

func (*MongoDB) EstimatedDocumentCount

func (m *MongoDB) EstimatedDocumentCount(ctx context.Context) (int64, error)

func (*MongoDB) Find

func (m *MongoDB) Find(ctx context.Context, result any) error

func (*MongoDB) FindByPage

func (m *MongoDB) FindByPage(ctx context.Context, paging *Paging, result any) (err error)

func (*MongoDB) FindOne

func (m *MongoDB) FindOne(ctx context.Context, result any) error

func (*MongoDB) FindOneAndDelete

func (m *MongoDB) FindOneAndDelete(ctx context.Context, result any) error

func (*MongoDB) FindOneAndUpdate

func (m *MongoDB) FindOneAndUpdate(ctx context.Context, update any, result any, opts ...options.Lister[options.FindOneAndUpdateOptions]) error

func (*MongoDB) InsertMany

func (m *MongoDB) InsertMany(ctx context.Context, documents []any) ([]any, error)

func (*MongoDB) InsertOne

func (m *MongoDB) InsertOne(ctx context.Context, document any) (any, error)

func (*MongoDB) UpdateById

func (m *MongoDB) UpdateById(ctx context.Context, id, update any, opts ...options.Lister[options.UpdateOneOptions]) error

func (*MongoDB) UpdateMany

func (m *MongoDB) UpdateMany(ctx context.Context, update any, opts ...options.Lister[options.UpdateManyOptions]) error

func (*MongoDB) UpdateOne

func (m *MongoDB) UpdateOne(ctx context.Context, update any, opts ...options.Lister[options.UpdateOneOptions]) error

type Paging

type Paging struct {
	Page      int64 // 当前页
	PageSize  int64 // 每页条数
	Total     int64 // 总条数
	PageCount int64 // 总页数
	StartNums int64 // 起始条数
	EndNums   int64 // 结束条数
}

func (*Paging) GetPages

func (p *Paging) GetPages()

获取分页信息

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL