update:github.com/mongodb/mongo-go-driver v2.0 Migration (#4687)

This commit is contained in:
me-cs
2025-08-09 21:21:53 +08:00
committed by GitHub
parent f36e5fed35
commit b41b1b00df
22 changed files with 2515 additions and 1174 deletions

View File

@@ -7,9 +7,8 @@ import (
"time"
"github.com/stretchr/testify/assert"
"go.mongodb.org/mongo-driver/bson/bsoncodec"
"go.mongodb.org/mongo-driver/bson/bsonrw"
mopt "go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/v2/bson"
mopt "go.mongodb.org/mongo-driver/v2/mongo/options"
)
func TestSetSlowThreshold(t *testing.T) {
@@ -60,7 +59,7 @@ func TestWithRegistryForTimestampRegisterType(t *testing.T) {
opts := mopt.Client()
// mongoDateTimeEncoder allow user convert time.Time to primitive.DateTime.
var mongoDateTimeEncoder bsoncodec.ValueEncoderFunc = func(ect bsoncodec.EncodeContext, w bsonrw.ValueWriter, value reflect.Value) error {
var mongoDateTimeEncoder bson.ValueEncoderFunc = func(ect bson.EncodeContext, w bson.ValueWriter, value reflect.Value) error {
// Use reflect, determine if it can be converted to time.Time.
dec, ok := value.Interface().(time.Time)
if !ok {
@@ -70,7 +69,7 @@ func TestWithRegistryForTimestampRegisterType(t *testing.T) {
}
// mongoDateTimeEncoder allow user convert primitive.DateTime to time.Time.
var mongoDateTimeDecoder bsoncodec.ValueDecoderFunc = func(ect bsoncodec.DecodeContext, r bsonrw.ValueReader, value reflect.Value) error {
var mongoDateTimeDecoder bson.ValueDecoderFunc = func(ect bson.DecodeContext, r bson.ValueReader, value reflect.Value) error {
primTime, err := r.ReadDateTime()
if err != nil {
return fmt.Errorf("error reading primitive.DateTime from ValueReader: %v", err)