Documentation ¶
Index ¶
- Constants
- Variables
- func Aggregate(result interface{}, dbName, collName string, pipeline interface{}, ...) error
- func BulkWrite(dbName, collName string, models []mongo.WriteModel, ...) error
- func Collection(projectId, collection string) *mongo.Collection
- func Count(dbName, collName string, filter interface{}, opts ...*options.CountOptions) (int64, error)
- func DB(projectId string, dbname string) *mongo.Database
- func DecodeAll(cursor *mongo.Cursor, ctx context.Context, result interface{}) (err error)
- func DeleteMany(dbName, collName string, filter interface{}, opts ...*options.DeleteOptions) error
- func DeleteOne(dbName, collName string, filter interface{}, opts ...*options.DeleteOptions) error
- func EnsureExpireIndex(db *mongo.Database, collection string, expireTime int32, keys ...string)
- func EnsureIndex(db *mongo.Database, collection string, keys ...string)
- func EnsureUniqIndex(db *mongo.Database, collection string, keys ...string)
- func FindAll(result interface{}, dbName, collName string, query interface{}, ...) error
- func FindOne(result interface{}, proj string, collName string, query interface{}, ...) error
- func FindOneAndDelete(dbName, collName string, filter interface{}, ...) error
- func FindOneAndUpdate(dbName, collName string, filter interface{}, update interface{}, ...) error
- func GetCustomTLSConfig(caFile string) (*tls.Config, error)
- func Init(adds map[string]string, prom bool)
- func InsertMany(dbName, collName string, documents []interface{}, ...) (*mongo.InsertManyResult, error)
- func InsertOne(dbName, collName string, document interface{}, ...) (interface{}, error)
- func NewInt64(value int64) *int64
- func NewString(value string) *string
- func NewTrue() *bool
- func SetFindClient(Func GetClientFunc)
- func UpdateAll(dbName, collName string, filter interface{}, update interface{}, ...) error
- func UpdateOne(dbName, collName string, filter interface{}, update interface{}, ...) error
- func UpsertOne(dbName, collName string, filter interface{}, update interface{}, ...) error
- type GetClientFunc
- type MongoClient
- func NewClient(prom bool, opts ...*options.ClientOptions) (*MongoClient, error)
- func NewDocumentClient(uri, CAFile string) (*MongoClient, error)
- func NewDocumentClientWithProm(uri, CAFile string) (*MongoClient, error)
- func NewMongoClient(uri string) (*MongoClient, error)
- func NewMongoClientWithProm(uri string, prom bool) (*MongoClient, error)
- func (c *MongoClient) Aggregate(result interface{}, dbName, collName string, pipeline interface{}, ...) (err error)
- func (c *MongoClient) BulkWrite(dbName, collName string, models []mongo.WriteModel, ...) (err error)
- func (c *MongoClient) Count(dbName, collName string, filter interface{}, opts ...*options.CountOptions) (count int64, err error)
- func (c *MongoClient) Database(name string) *mongo.Database
- func (c *MongoClient) DbColl(dbName, coll string) *mongo.Collection
- func (c *MongoClient) DeleteMany(dbName, collName string, filter interface{}, opts ...*options.DeleteOptions) (err error)
- func (c *MongoClient) DeleteOne(dbName, collName string, filter interface{}, opts ...*options.DeleteOptions) (err error)
- func (c *MongoClient) FindAll(result interface{}, dbName, collName string, query interface{}, ...) (err error)
- func (c *MongoClient) FindOne(result interface{}, dbName, collName string, query interface{}, ...) (err error)
- func (c *MongoClient) FindOneAndDelete(dbName, collName string, filter interface{}, ...) (err error)
- func (c *MongoClient) FindOneAndUpdate(dbName, collName string, filter interface{}, update interface{}, ...) (err error)
- func (c *MongoClient) InsertMany(dbName, collName string, documents []interface{}, ...) (result *mongo.InsertManyResult, err error)
- func (c *MongoClient) InsertOne(dbName, collName string, document interface{}, ...) (insertedID interface{}, err error)
- func (c *MongoClient) UpdateAll(dbName, collName string, filter interface{}, update interface{}, ...) (err error)
- func (c *MongoClient) UpdateOne(dbName, collName string, filter interface{}, update interface{}, ...) (err error)
- func (c *MongoClient) UpsertOne(dbName, collName string, filter interface{}, update interface{}, ...) (err error)
- type MyCursor
Constants ¶
View Source
const ( // MongoConnPoolLimit is the maximum number of sockets in use in a single server // before this session will block waiting for a socket to be available. // The default limit is 4096. // // This limit must be set to cover more than any expected workload of the // application. It is a bad practice and an unsupported use case to use the // database driver to define the concurrency limit of an application. Prevent // such concurrency "at the door" instead, by properly restricting the amount // of used resources and number of goroutines before they are created. MongoConnPoolLimit = 128 )
Variables ¶
View Source
var ( ClientMap map[string]*MongoClient CommonClient *MongoClient IsInit bool )
Functions ¶
func Aggregate ¶
func Aggregate(result interface{}, dbName, collName string, pipeline interface{}, opts ...*options.AggregateOptions) error
func BulkWrite ¶
func BulkWrite(dbName, collName string, models []mongo.WriteModel, opts ...*options.BulkWriteOptions) error
func Collection ¶
func Collection(projectId, collection string) *mongo.Collection
func Count ¶
func Count(dbName, collName string, filter interface{}, opts ...*options.CountOptions) (int64, error)
func DeleteMany ¶
func DeleteMany(dbName, collName string, filter interface{}, opts ...*options.DeleteOptions) error
func DeleteOne ¶
func DeleteOne(dbName, collName string, filter interface{}, opts ...*options.DeleteOptions) error
func EnsureExpireIndex ¶
func FindAll ¶
func FindAll(result interface{}, dbName, collName string, query interface{}, opts ...*options.FindOptions) error
func FindOne ¶
func FindOne(result interface{}, proj string, collName string, query interface{}, opts ...*options.FindOneOptions) error
func FindOneAndDelete ¶
func FindOneAndDelete(dbName, collName string, filter interface{}, opts ...*options.FindOneAndDeleteOptions) error
func FindOneAndUpdate ¶
func FindOneAndUpdate(dbName, collName string, filter interface{}, update interface{}, opts ...*options.FindOneAndUpdateOptions) error
func GetCustomTLSConfig ¶
GetCustomTLSConfig 获取TLS证书
func InsertMany ¶
func InsertMany(dbName, collName string, documents []interface{}, opts ...*options.InsertManyOptions) (*mongo.InsertManyResult, error)
func InsertOne ¶
func InsertOne(dbName, collName string, document interface{}, opts ...*options.InsertOneOptions) (interface{}, error)
func SetFindClient ¶
func SetFindClient(Func GetClientFunc)
SetFindClient If you want select client by yourself you can do it
func UpdateAll ¶
func UpdateAll(dbName, collName string, filter interface{}, update interface{}, opts ...*options.UpdateOptions) error
Types ¶
type GetClientFunc ¶
type GetClientFunc func(projectId string) (*MongoClient, error)
GetClientFunc You can select your client by yourself
var GetClient GetClientFunc = func(projectId string) (client *MongoClient, err error) { if !IsInit { err = errors.New("Mongo Client is not init!") return } if c, ok := ClientMap[projectId]; ok { client = c } else { client = CommonClient } return }
GetClient default GetClient func is get client from ClientMap
type MongoClient ¶
type MongoClient struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(prom bool, opts ...*options.ClientOptions) (*MongoClient, error)
NewClient NewMongoClient create MongoClient by your options.ClientOptions
func NewDocumentClient ¶
func NewDocumentClient(uri, CAFile string) (*MongoClient, error)
NewDocumentClient create MongoClient use default options.ClientOptions and TLS
func NewDocumentClientWithProm ¶
func NewDocumentClientWithProm(uri, CAFile string) (*MongoClient, error)
NewDocumentClientWithProm create MongoClient use Prom Monitor
func NewMongoClient ¶
func NewMongoClient(uri string) (*MongoClient, error)
NewMongoClient create MongoClient use default options.ClientOptions
func NewMongoClientWithProm ¶
func NewMongoClientWithProm(uri string, prom bool) (*MongoClient, error)
NewMongoClientWithProm create MongoClient use Prom Monitor
func (*MongoClient) Aggregate ¶
func (c *MongoClient) Aggregate(result interface{}, dbName, collName string, pipeline interface{}, opts ...*options.AggregateOptions) (err error)
func (*MongoClient) BulkWrite ¶
func (c *MongoClient) BulkWrite(dbName, collName string, models []mongo.WriteModel, opts ...*options.BulkWriteOptions) (err error)
func (*MongoClient) Count ¶
func (c *MongoClient) Count(dbName, collName string, filter interface{}, opts ...*options.CountOptions) (count int64, err error)
func (*MongoClient) DbColl ¶
func (c *MongoClient) DbColl(dbName, coll string) *mongo.Collection
func (*MongoClient) DeleteMany ¶
func (c *MongoClient) DeleteMany(dbName, collName string, filter interface{}, opts ...*options.DeleteOptions) (err error)
func (*MongoClient) DeleteOne ¶
func (c *MongoClient) DeleteOne(dbName, collName string, filter interface{}, opts ...*options.DeleteOptions) (err error)
func (*MongoClient) FindAll ¶
func (c *MongoClient) FindAll(result interface{}, dbName, collName string, query interface{}, opts ...*options.FindOptions) (err error)
func (*MongoClient) FindOne ¶
func (c *MongoClient) FindOne(result interface{}, dbName, collName string, query interface{}, opts ...*options.FindOneOptions) (err error)
func (*MongoClient) FindOneAndDelete ¶
func (c *MongoClient) FindOneAndDelete(dbName, collName string, filter interface{}, opts ...*options.FindOneAndDeleteOptions) (err error)
func (*MongoClient) FindOneAndUpdate ¶
func (c *MongoClient) FindOneAndUpdate(dbName, collName string, filter interface{}, update interface{}, opts ...*options.FindOneAndUpdateOptions) (err error)
func (*MongoClient) InsertMany ¶
func (c *MongoClient) InsertMany(dbName, collName string, documents []interface{}, opts ...*options.InsertManyOptions) (result *mongo.InsertManyResult, err error)
func (*MongoClient) InsertOne ¶
func (c *MongoClient) InsertOne(dbName, collName string, document interface{}, opts ...*options.InsertOneOptions) (insertedID interface{}, err error)
func (*MongoClient) UpdateAll ¶
func (c *MongoClient) UpdateAll(dbName, collName string, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (err error)
func (*MongoClient) UpdateOne ¶
func (c *MongoClient) UpdateOne(dbName, collName string, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (err error)
func (*MongoClient) UpsertOne ¶
func (c *MongoClient) UpsertOne(dbName, collName string, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (err error)
Click to show internal directories.
Click to hide internal directories.