Documentation ¶
Index ¶
- func CreateDefaultDB(config *Config) error
- func NewClient(cfg *Config) (mc *mongo.Client, err error)
- func NewStarter() *starter
- func XClient() *mongo.Client
- func XFClient(f func(c *mongo.Client) error) error
- type CommonMongoDao
- func (mp *CommonMongoDao) Aggregate(ctx context.Context, collectionName string, pipline interface{}, ...) (cursor *mongo.Cursor, err error)
- func (mp *CommonMongoDao) BulkWrite(ctx context.Context, collectionName string, models []mongo.WriteModel, ...) (bulkResult *mongo.BulkWriteResult, err error)
- func (mp *CommonMongoDao) CountDocuments(ctx context.Context, collectionName string, filter interface{}, ...) (int64, error)
- func (mp *CommonMongoDao) DM(dbName, colName string, f func(c *mongo.Collection) error) error
- func (mp *CommonMongoDao) DeleteMany(ctx context.Context, collectionName string, filter interface{}, ...) (deleteCount int64, err error)
- func (mp *CommonMongoDao) DeleteOne(ctx context.Context, collectionName string, filter interface{}, ...) (deleteCount int64, err error)
- func (mp *CommonMongoDao) Find(ctx context.Context, collectionName string, filter interface{}, ...) (cursor *mongo.Cursor, err error)
- func (mp *CommonMongoDao) FindOne(ctx context.Context, collectionName string, filter interface{}, ...) *mongo.SingleResult
- func (mp *CommonMongoDao) FindOneAndDelete(ctx context.Context, collectionName string, filter interface{}, ...) (singleResult *mongo.SingleResult)
- func (mp *CommonMongoDao) FindOneAndReplace(ctx context.Context, collectionName string, filter interface{}, ...) (singleResult *mongo.SingleResult)
- func (mp *CommonMongoDao) FindOneAndUpdate(ctx context.Context, collectionName string, filter, updater interface{}, ...) (result *mongo.SingleResult)
- func (mp *CommonMongoDao) InsertMany(ctx context.Context, collectionName string, documents []interface{}, ...) (insertIDs []interface{}, err error)
- func (mp *CommonMongoDao) InsertOne(ctx context.Context, collectionName string, document interface{}, ...) (insertID interface{}, err error)
- func (mp *CommonMongoDao) M(colName string, f func(c *mongo.Collection) error) error
- func (mp *CommonMongoDao) ReplaceOne(ctx context.Context, collectionName string, filter, replacement interface{}, ...) (result *mongo.UpdateResult, err error)
- func (mp *CommonMongoDao) UpdateMany(ctx context.Context, collectionName string, filter, updater interface{}, ...) (result *mongo.UpdateResult, err error)
- func (mp *CommonMongoDao) UpdateOne(ctx context.Context, collectionName string, filter, updater interface{}, ...) (result *mongo.UpdateResult, err error)
- type Config
- type FindResult
- type FindResults
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewStarter ¶
func NewStarter() *starter
Types ¶
type CommonMongoDao ¶
type CommonMongoDao struct {
// contains filtered or unexported fields
}
func (*CommonMongoDao) Aggregate ¶
func (mp *CommonMongoDao) Aggregate(ctx context.Context, collectionName string, pipline interface{}, opts ...*options.AggregateOptions) (cursor *mongo.Cursor, err error)
聚合计算
func (*CommonMongoDao) BulkWrite ¶
func (mp *CommonMongoDao) BulkWrite(ctx context.Context, collectionName string, models []mongo.WriteModel, opts ...*options.BulkWriteOptions) (bulkResult *mongo.BulkWriteResult, err error)
批量操作
func (*CommonMongoDao) CountDocuments ¶
func (mp *CommonMongoDao) CountDocuments(ctx context.Context, collectionName string, filter interface{}, opts ...*options.CountOptions) (int64, error)
查找文档数
func (*CommonMongoDao) DM ¶
func (mp *CommonMongoDao) DM(dbName, colName string, f func(c *mongo.Collection) error) error
func (*CommonMongoDao) DeleteMany ¶
func (mp *CommonMongoDao) DeleteMany(ctx context.Context, collectionName string, filter interface{}, opts ...*options.DeleteOptions) (deleteCount int64, err error)
func (*CommonMongoDao) DeleteOne ¶
func (mp *CommonMongoDao) DeleteOne(ctx context.Context, collectionName string, filter interface{}, opts ...*options.DeleteOptions) (deleteCount int64, err error)
通用删除数据
func (*CommonMongoDao) Find ¶
func (mp *CommonMongoDao) Find(ctx context.Context, collectionName string, filter interface{}, opts ...*options.FindOptions) (cursor *mongo.Cursor, err error)
查找文档
func (*CommonMongoDao) FindOne ¶
func (mp *CommonMongoDao) FindOne(ctx context.Context, collectionName string, filter interface{}, opts ...*options.FindOneOptions) *mongo.SingleResult
func (*CommonMongoDao) FindOneAndDelete ¶
func (mp *CommonMongoDao) FindOneAndDelete(ctx context.Context, collectionName string, filter interface{}, opts ...*options.FindOneAndDeleteOptions) (singleResult *mongo.SingleResult)
func (*CommonMongoDao) FindOneAndReplace ¶
func (mp *CommonMongoDao) FindOneAndReplace(ctx context.Context, collectionName string, filter interface{}, replacement interface{}, opts ...*options.FindOneAndReplaceOptions) (singleResult *mongo.SingleResult)
func (*CommonMongoDao) FindOneAndUpdate ¶
func (mp *CommonMongoDao) FindOneAndUpdate(ctx context.Context, collectionName string, filter, updater interface{}, opts ...*options.FindOneAndUpdateOptions) (result *mongo.SingleResult)
func (*CommonMongoDao) InsertMany ¶
func (mp *CommonMongoDao) InsertMany(ctx context.Context, collectionName string, documents []interface{}, opts ...*options.InsertManyOptions) (insertIDs []interface{}, err error)
func (*CommonMongoDao) InsertOne ¶
func (mp *CommonMongoDao) InsertOne(ctx context.Context, collectionName string, document interface{}, opts ...*options.InsertOneOptions) (insertID interface{}, err error)
通用新增数据到mongo collection
func (*CommonMongoDao) M ¶
func (mp *CommonMongoDao) M(colName string, f func(c *mongo.Collection) error) error
func (*CommonMongoDao) ReplaceOne ¶
func (mp *CommonMongoDao) ReplaceOne(ctx context.Context, collectionName string, filter, replacement interface{}, opts ...*options.ReplaceOptions) (result *mongo.UpdateResult, err error)
func (*CommonMongoDao) UpdateMany ¶
func (mp *CommonMongoDao) UpdateMany(ctx context.Context, collectionName string, filter, updater interface{}, opts ...*options.UpdateOptions) (result *mongo.UpdateResult, err error)
func (*CommonMongoDao) UpdateOne ¶
func (mp *CommonMongoDao) UpdateOne(ctx context.Context, collectionName string, filter, updater interface{}, opts ...*options.UpdateOptions) (result *mongo.UpdateResult, err error)
通用更新数据
type Config ¶
type Config struct { DbHosts []string DbUser string DbPasswd string Database string ReplicaSet string // 指定群集的副本集名称。如果指定,集群将被视为副本集,驱动程序将自动发现集中的所有服务器,从通过ApplyURI或SetHosts指定的节点开始。副本集中的所有节点必须具有相同的副本集名称,否则客户端不会将它们视为该集的一部分。 PasswordSet bool // 对于GSSAPI,如果指定了密码,则此值必须为true,即使密码是空字符串,并且 如果未指定密码,则为false,表示应从运行的上下文中获取密码 过程。对于其他机制,此字段将被忽略。 LocalThreshold int // 指定“延迟窗口”的宽度:在为一个操作选择多个合适的服务器时,这是最短和最长平均往返时间之间可接受的非负增量。延迟窗口中的服务器是随机选择的。默认值为15毫秒。 Compressors []string // 通信数据压缩器,可多选 Direct bool // 是否单机直连 HeartbeatInterval int // 定期连接心跳检查,不设置默认10s MinPoolSize uint64 // 最小连接池连接数 MaxPoolSize uint64 // 最大连接池连接数 MaxConnIdleTime uint64 // 连接池闲置连结束最大保持时间,0时表示无限制保持闲置连接状态 AutoEncryptionOptions bool // 作用于collection的自动加密 ConnectTimeout int // 接超时时间,单位秒 RetryReads bool // 指定是否应在某些错误(如网络)上重试一次受支持的读操作 RetryWrites bool // 指定是否应在某些错误(如网络)上重试一次受支持的写入操作 }
MongoDB 配置
func DefaultConfig ¶
func DefaultConfig() *Config
type FindResult ¶
type FindResult interface{}
type FindResults ¶
type FindResults []interface{}
Click to show internal directories.
Click to hide internal directories.