diff --git a/bson/constructor.go b/bson/constructor.go index a0a101ca03..8932ac460d 100644 --- a/bson/constructor.go +++ b/bson/constructor.go @@ -331,7 +331,7 @@ func (ElementConstructor) DateTime(key string, dt int64) *Element { // Time creates a datetime element with the given key and value. func (c ElementConstructor) Time(key string, t time.Time) *Element { // Apply nanoseconds to milliseconds conversion - return c.DateTime(key, convertTimeToInt64(t)) + return c.DateTime(key, t.Unix()*1000+int64(t.Nanosecond()/1e6)) } // Null creates a null element with the given key. diff --git a/mongo/crud_util_test.go b/mongo/crud_util_test.go index 9318ad33c3..56889e7f95 100644 --- a/mongo/crud_util_test.go +++ b/mongo/crud_util_test.go @@ -10,11 +10,12 @@ import ( "bytes" "context" "encoding/json" - "github.com/mongodb/mongo-go-driver/bson/bsoncodec" "math" "strings" "testing" + "github.com/mongodb/mongo-go-driver/bson/bsoncodec" + "github.com/mongodb/mongo-go-driver/bson" "github.com/mongodb/mongo-go-driver/core/readconcern" "github.com/mongodb/mongo-go-driver/core/writeconcern" @@ -570,7 +571,7 @@ func verifyBulkWriteResult(t *testing.T, res *BulkWriteResult, result json.RawMe // replace floats with ints for opID, upsertID := range expected.UpsertedIDs { if floatID, ok := upsertID.(float64); ok { - expected.UpsertedIDs[opID] = int64(floatID) + expected.UpsertedIDs[opID] = int32(floatID) } }