Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}