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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.bson
.idea
2 changes: 1 addition & 1 deletion bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"testing"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/v2/bson"
)

func BenchmarkMemoryStoreWrite(b *testing.B) {
Expand Down
2 changes: 1 addition & 1 deletion bsonkit/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strconv"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/v2/bson"
)

// MissingType is the type of the Missing value.
Expand Down
2 changes: 1 addition & 1 deletion bsonkit/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/v2/bson"
)

func TestGet(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion bsonkit/bsonkit.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package bsonkit

import "go.mongodb.org/mongo-driver/bson"
import "go.mongodb.org/mongo-driver/v2/bson"

// Doc is a full document that may contain fields, arrays and embedded documents.
// The pointer form is chosen to identify the document uniquely (pointer address).
Expand Down
7 changes: 3 additions & 4 deletions bsonkit/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package bsonkit
import (
"fmt"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
)

// Clone will clone the specified document. The returned document can be safely
Expand Down Expand Up @@ -52,10 +51,10 @@ func cloneValue(v interface{}) interface{} {
case nil, int32, int64, float64, string, bool:
// primitives do not need cloning
return value
case primitive.Null, primitive.ObjectID, primitive.DateTime, primitive.Timestamp, primitive.Regex, primitive.Decimal128:
case bson.Null, bson.ObjectID, bson.DateTime, bson.Timestamp, bson.Regex, bson.Decimal128:
// structures of primitives do not need cloning
return value
case primitive.Binary:
case bson.Binary:
// do not clone binary data as they do not get mutated themselves
return value
case bson.D:
Expand Down
2 changes: 1 addition & 1 deletion bsonkit/clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/v2/bson"
)

func TestClone(t *testing.T) {
Expand Down
35 changes: 17 additions & 18 deletions bsonkit/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
"strings"

"github.com/shopspring/decimal"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
)

// Compare will compare two bson values and return their order according to the
Expand Down Expand Up @@ -64,7 +63,7 @@ func compareNumbers(lv, rv interface{}) int {
return compareFloat64s(l, float64(r))
case int64:
return compareFloat64ToInt64(l, r)
case primitive.Decimal128:
case bson.Decimal128:
return decimal.NewFromFloat(l).Cmp(d128ToDec(r))
}
case int32:
Expand All @@ -75,7 +74,7 @@ func compareNumbers(lv, rv interface{}) int {
return compareInt32s(l, r)
case int64:
return compareInt64s(int64(l), r)
case primitive.Decimal128:
case bson.Decimal128:
return decimal.NewFromInt32(l).Cmp(d128ToDec(r))
}
case int64:
Expand All @@ -86,18 +85,18 @@ func compareNumbers(lv, rv interface{}) int {
return compareInt64s(l, int64(r))
case int64:
return compareInt64s(l, r)
case primitive.Decimal128:
case bson.Decimal128:
return decimal.NewFromInt(l).Cmp(d128ToDec(r))
}
case primitive.Decimal128:
case bson.Decimal128:
switch r := rv.(type) {
case float64:
return d128ToDec(l).Cmp(decimal.NewFromFloat(r))
case int32:
return d128ToDec(l).Cmp(decimal.NewFromInt32(r))
case int64:
return d128ToDec(l).Cmp(decimal.NewFromInt(r))
case primitive.Decimal128:
case bson.Decimal128:
return d128ToDec(l).Cmp(d128ToDec(r))
}
}
Expand Down Expand Up @@ -194,8 +193,8 @@ func compareArrays(lv, rv interface{}) int {

func compareBinaries(lv, rv interface{}) int {
// get binaries
l := lv.(primitive.Binary)
r := rv.(primitive.Binary)
l := lv.(bson.Binary)
r := rv.(bson.Binary)

// compare length
if len(l.Data) > len(r.Data) {
Expand All @@ -219,8 +218,8 @@ func compareBinaries(lv, rv interface{}) int {

func compareObjectIDs(lv, rv interface{}) int {
// get object ids
l := lv.(primitive.ObjectID)
r := rv.(primitive.ObjectID)
l := lv.(bson.ObjectID)
r := rv.(bson.ObjectID)

// compare object ids
res := bytes.Compare(l[:], r[:])
Expand All @@ -245,8 +244,8 @@ func compareBooleans(lv, rv interface{}) int {

func compareDates(lv, rv interface{}) int {
// get times
l := lv.(primitive.DateTime)
r := rv.(primitive.DateTime)
l := lv.(bson.DateTime)
r := rv.(bson.DateTime)

// compare times
if l == r {
Expand All @@ -260,19 +259,19 @@ func compareDates(lv, rv interface{}) int {

func compareTimestamps(lv, rv interface{}) int {
// get timestamps
l := lv.(primitive.Timestamp)
r := rv.(primitive.Timestamp)
l := lv.(bson.Timestamp)
r := rv.(bson.Timestamp)

// compare timestamps
ret := primitive.CompareTimestamp(l, r)
ret := l.Compare(r)

return ret
}

func compareRegexes(lv, rv interface{}) int {
// get regexes
l := lv.(primitive.Regex)
r := rv.(primitive.Regex)
l := lv.(bson.Regex)
r := rv.(bson.Regex)

// compare patterns
ret := strings.Compare(l.Pattern, r.Pattern)
Expand Down
5 changes: 2 additions & 3 deletions bsonkit/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
)

func TestCompare(t *testing.T) {
Expand All @@ -19,7 +18,7 @@ func TestCompare(t *testing.T) {
assert.Equal(t, 1, Compare(false, "foo"))

// decimal
dec, err := primitive.ParseDecimal128("3.14")
dec, err := bson.ParseDecimal128("3.14")
assert.NoError(t, err)
assert.Equal(t, 1, Compare(5.0, dec))
}
17 changes: 8 additions & 9 deletions bsonkit/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
"sort"
"time"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
)

// MustConvert will call Convert and panic on errors.
Expand Down Expand Up @@ -147,7 +146,7 @@ func ConvertValue(v interface{}) (interface{}, error) {
}
}
return a, nil
case []primitive.ObjectID:
case []bson.ObjectID:
a := make(bson.A, len(value))
for i, item := range value {
a[i] = item
Expand All @@ -157,20 +156,20 @@ func ConvertValue(v interface{}) (interface{}, error) {
return value, nil
case int:
return int64(value), nil
case primitive.Null, primitive.ObjectID, primitive.DateTime,
primitive.Timestamp, primitive.Regex, primitive.Decimal128,
primitive.Binary:
case bson.Null, bson.ObjectID, bson.DateTime,
bson.Timestamp, bson.Regex, bson.Decimal128,
bson.Binary:
return value, nil
case *primitive.ObjectID:
case *bson.ObjectID:
if value != nil {
return *value, nil
}
return nil, nil
case time.Time:
return primitive.NewDateTimeFromTime(value.UTC()), nil
return bson.NewDateTimeFromTime(value.UTC()), nil
case *time.Time:
if value != nil {
return primitive.NewDateTimeFromTime(value.UTC()), nil
return bson.NewDateTimeFromTime(value.UTC()), nil
}
return nil, nil
default:
Expand Down
5 changes: 2 additions & 3 deletions bsonkit/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
)

func TestConvert(t *testing.T) {
Expand Down Expand Up @@ -81,5 +80,5 @@ func TestConvertList(t *testing.T) {
func TestConvertValue(t *testing.T) {
now := time.Now()
res := MustConvertValue(now)
assert.Equal(t, primitive.NewDateTimeFromTime(now), res)
assert.Equal(t, bson.NewDateTimeFromTime(now), res)
}
2 changes: 1 addition & 1 deletion bsonkit/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/v2/bson"
)

func TestDecode(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion bsonkit/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/v2/bson"
)

func TestIndex(t *testing.T) {
Expand Down
Loading