mongo

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

README

mongo文档

####读写策略和读写分离 https://mongoing.com/archives/3403

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Conn               string `json:"conn" mapstructure:"conn"`
	CtxTimeout         int64  `mapstructure:"ctxTimeout"`
	Database           string `mapstructure:"database"`
	SetLocalThreshold  int    `mapstructure:"setLocalThreshold"`
	SetMaxConnIdleTime int    `mapstructure:"setMaxConnIdleTime"`
	SetMaxPoolSize     uint64 `mapstructure:"setMaxPoolSize"`
}

type Mongo

type Mongo struct {
	Config       Config
	Client       *mongo.Client
	Database     *mongo.Database
	IndexOptions *options.CreateIndexesOptions
	Collections  map[string]*mongo.Collection
}

func NewMongo

func NewMongo(c Config) (*Mongo, error)

NewMongo 连接mongo服务

func (*Mongo) CreateIndex

func (m *Mongo) CreateIndex(collection string, unique bool, keys ...string) error

CreateIndex 创建索引

func (*Mongo) GetCtx

func (m *Mongo) GetCtx() (ctx context.Context, ctxCancel context.CancelFunc)

GetCtx 返回ctx和ctxCancel

func (*Mongo) Register

func (m *Mongo) Register(name string) (err error)

Register 添加Collection

Jump to

Keyboard shortcuts

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