diff --git a/client.go b/client.go index f9c056d..e5e4187 100644 --- a/client.go +++ b/client.go @@ -312,12 +312,12 @@ func (c *Client) Session(opt ...*options.SessionOptions) (*Session, error) { // - version of mongoDB server >= v4.0 // - Topology of mongoDB server is not Single // At the same time, please pay attention to the following -// - make sure all operations in callback use the sessCtx as context parameter -// - if operations in callback takes more than(include equal) 120s, the operations will not take effect, -// - if operation in callback return qmgo.ErrTransactionRetry, -// the whole transaction will retry, so this transaction must be idempotent -// - if operations in callback return qmgo.ErrTransactionNotSupported, -// - If the ctx parameter already has a Session attached to it, it will be replaced by this session. +// - make sure all operations in callback use the sessCtx as context parameter +// - if operations in callback takes more than(include equal) 120s, the operations will not take effect, +// - if operation in callback return qmgo.ErrTransactionRetry, +// the whole transaction will retry, so this transaction must be idempotent +// - if operations in callback return qmgo.ErrTransactionNotSupported, +// - If the ctx parameter already has a Session attached to it, it will be replaced by this session. func (c *Client) DoTransaction(ctx context.Context, callback func(sessCtx context.Context) (interface{}, error), opts ...*options.TransactionOptions) (interface{}, error) { if !c.transactionAllowed() { return nil, ErrTransactionNotSupported @@ -368,3 +368,8 @@ func (c *Client) transactionAllowed() bool { //} return true } + +// AsMongoDriver exposes the ofiicial mongo driver `mongo.Database` for senior use +func (c *Client) AsMongoDriver() *mongo.Client { + return c.client +} diff --git a/collection.go b/collection.go index 9af5d62..c80e4d9 100644 --- a/collection.go +++ b/collection.go @@ -576,3 +576,8 @@ func translateUpdateResult(res *mongo.UpdateResult) (result *UpdateResult) { } return } + +// AsMongoDriver exposes the ofiicial mongo driver `mongo.Collection` for senior use +func (c *Collection) AsMongoDriver() *mongo.Collection { + return c.collection +} diff --git a/cursor.go b/cursor.go index 60b46cc..d84f0b1 100644 --- a/cursor.go +++ b/cursor.go @@ -76,3 +76,8 @@ func (c *Cursor) Err() error { } return c.cursor.Err() } + +// AsMongoDriver exposes the ofiicial mongo driver `mongo.Cursor` for senior use +func (c *Cursor) AsMongoDriver() *mongo.Cursor { + return c.cursor +} diff --git a/database.go b/database.go index 3546e39..c1c1824 100644 --- a/database.go +++ b/database.go @@ -85,3 +85,8 @@ func (db *Database) CreateCollection(ctx context.Context, name string, opts ...o } return db.database.CreateCollection(ctx, name, option...) } + +// AsMongoDriver exposes the ofiicial mongo driver `mongo.Database` for senior use +func (db *Database) AsMongoDriver() *mongo.Database { + return db.database +}