Documentation ¶
Index ¶
- Constants
- Variables
- func InitMongoClient(clientName, username, password string, addrs []string, mongoPoolLimit uint64) error
- type CursorCallBackFunc
- type MgClient
- func (client *MgClient) AggregateUseCursor(db string, table string, queries []bson.D, rowType interface{}, ...) error
- func (client *MgClient) Close()
- func (client *MgClient) CopyTable(db, table, newTable string) (bool, error)
- func (client *MgClient) CreateIndex(db, table, key string, uniqueKey bool) error
- func (client *MgClient) CreateMultiIndex(db, table string, keys []string, uniqueKey bool) error
- func (client *MgClient) DeleteMany(db string, table string, filter bson.D) error
- func (client *MgClient) DeleteOne(db string, table string, filter bson.D) error
- func (client *MgClient) Distinct(db, table string, filter bson.D, distinctField string) (result []interface{}, err error)
- func (client *MgClient) Drop(db, table string) error
- func (client *MgClient) EstimatedDocumentCount(db, table string) (int64, error)
- func (client *MgClient) Find(db string, table string, filter bson.D, result interface{}) (bool, error)
- func (client *MgClient) FindByID(db, table string, id interface{}, resultObj interface{}) error
- func (client *MgClient) FindOne(db, table string, filter bson.D, resultObj interface{}) error
- func (client *MgClient) FindUseCursor(db string, table string, batchSize int32, filter bson.D, rowType interface{}, ...) error
- func (client *MgClient) FindUseCursorWithOptions(db string, table string, batchSize int32, filter bson.D, rowType interface{}, ...) error
- func (client *MgClient) FindWithOpts(db string, table string, offset, limit int64, filter interface{}, ...) (bool, error)
- func (client *MgClient) FindWithOrder(db string, table string, filter bson.D, orders map[string]int, ...) (bool, error)
- func (client *MgClient) InsertMany(db string, table string, docs ...interface{}) error
- func (client *MgClient) InsertManyTryBest(db string, table string, docs ...interface{}) error
- func (client *MgClient) QueryCount(db, table string, filter bson.D, defaultVal int) (int64, error)
- func (client *MgClient) RenameTable(db, table, newTable string) error
- func (client *MgClient) ReplaceOne(db string, table string, filter bson.D, doc interface{}) error
- func (client *MgClient) UpdateMany(db string, table string, filter bson.D, update interface{}) error
- func (client *MgClient) UpdateOne(db string, table string, filter bson.D, update interface{}) error
- func (client *MgClient) Upsert(db string, table string, filter bson.D, doc interface{}) error
Constants ¶
View Source
const ( DefaultMongoClient = "default-mongo" DefaultConnectTimeout = 3 * time.Second )
Variables ¶
View Source
var (
MongoStdLogger stdLogger
)
Functions ¶
Types ¶
type CursorCallBackFunc ¶
type CursorCallBackFunc func(res interface{}, err error)
type MgClient ¶
func GetMongoClient ¶
func (*MgClient) AggregateUseCursor ¶
func (*MgClient) CreateIndex ¶
CreateIndex .
func (*MgClient) CreateMultiIndex ¶
创建多个索引
func (*MgClient) DeleteMany ¶
func (*MgClient) EstimatedDocumentCount ¶
通过metadata获取整个集合中总记录数
func (*MgClient) FindUseCursor ¶
func (*MgClient) FindUseCursorWithOptions ¶
func (client *MgClient) FindUseCursorWithOptions(db string, table string, batchSize int32, filter bson.D, rowType interface{}, opts *options.FindOptions, cursorCallbackFunc CursorCallBackFunc) error
func (*MgClient) FindWithOpts ¶
func (*MgClient) FindWithOrder ¶
func (*MgClient) InsertMany ¶
example InsertMany("db","table",bson.D{{"name", "Alice"}},bson.D{{"name", "Bob"}})
func (*MgClient) InsertManyTryBest ¶
上面的InsertMany在遇到异常的时候(比如插入mongo集群中已存在的数据),全部文档都会插入失败 这个方法则忽略异常的文档,将没出问题的这部分文档写入到mongo 检测插入过程的错误可以使用下面的方式 err := GetMongoClient(DefaultMongoClient).InsertManyTryBest("db", "table", doc) we, ok := err.(mongo.BulkWriteException) if ok { TO DO ... } 出现重复文档的code = 11000 if we.HasErrorCode(11000) { TO DO ... }
func (*MgClient) QueryCount ¶
func (*MgClient) RenameTable ¶
func (*MgClient) ReplaceOne ¶
func (*MgClient) UpdateMany ¶
func (client *MgClient) UpdateMany(db string, table string, filter bson.D, update interface{}) error
example filter := bson.D{{"birthday", today}} update := bson.D{{"$inc", bson.D{{"age", 1}}}}
Click to show internal directories.
Click to hide internal directories.