Skip to content

Commit

Permalink
More tests for dot notation support (#660)
Browse files Browse the repository at this point in the history
Refs #632.
  • Loading branch information
Dmitry committed Jun 6, 2022
1 parent 0b54a31 commit d03d6a0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 26 deletions.
2 changes: 1 addition & 1 deletion integration/query_comparison_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestQueryComparisonImplicit(t *testing.T) {
expectedIDs: []any{},
},
"ArrayDotNotationNoSuchField": {
filter: bson.D{{"value.some[0]", bson.A{42}}},
filter: bson.D{{"value.some.0", bson.A{42}}},
expectedIDs: []any{},
},

Expand Down
60 changes: 40 additions & 20 deletions integration/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,38 +640,58 @@ func TestQueryExactMatches(t *testing.T) {

func TestDotNotation(t *testing.T) {
t.Parallel()
providers := []shareddata.Provider{shareddata.Scalars, shareddata.Composites}
ctx, collection := setup(t, providers...)

_, err := collection.InsertMany(ctx, []any{
bson.D{
{"_id", "document-deeply-nested"},
{
"foo",
bson.D{{
"bar",
bson.D{{
"baz",
bson.D{{"qux", bson.D{{"quz", int32(42)}}}},
}},
}},
},
},
})
ctx, collection := setup(t)

_, err := collection.InsertMany(
ctx,
[]any{
bson.D{
{"_id", "document-deeply-nested"},
{
"foo",
bson.D{
{
"bar",
bson.D{{
"baz",
bson.D{{"qux", bson.D{{"quz", int32(42)}}}},
}},
},
{
"qaz",
bson.A{bson.D{{"baz", int32(1)}}},
},
},
},
{
"wsx",
bson.A{bson.D{{"edc", bson.A{bson.D{{"rfv", int32(1)}}}}}},
},
},
},
)
require.NoError(t, err)

for name, tc := range map[string]struct {
filter bson.D
expectedIDs []any
}{
"DocumentDeepNested": {
"DeeplyNested": {
filter: bson.D{{"foo.bar.baz.qux.quz", int32(42)}},
expectedIDs: []any{"document-deeply-nested"},
},
"Document": {
"DottedField": {
filter: bson.D{{"foo.bar.baz", bson.D{{"qux.quz", int32(42)}}}},
expectedIDs: []any{},
},
"FieldArrayField": {
filter: bson.D{{"foo.qaz.0.baz", int32(1)}},
expectedIDs: []any{"document-deeply-nested"},
},
"FieldArrayFieldArrayField": {
filter: bson.D{{"wsx.0.edc.0.rfv", int32(1)}},
expectedIDs: []any{"document-deeply-nested"},
},
} {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
Expand Down
6 changes: 1 addition & 5 deletions internal/handlers/common/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ func UpdateDocument(doc, update *types.Document) (bool, error) {
incDoc := updateV.(*types.Document)

for _, incKey := range incDoc.Keys() {
if strings.ContainsRune(incKey, '.') {
return false, NewErrorMsg(ErrNotImplemented, "dot notation not supported yet")
}

incValue := must.NotFail(incDoc.Get(incKey))

if !doc.Has(incKey) {
Expand Down Expand Up @@ -215,7 +211,7 @@ func extractValueFromUpdateOperator(op string, update *types.Document) (*types.D
case *types.Document:
for _, v := range doc.Keys() {
if strings.Contains(v, ".") {
return nil, NewError(ErrNotImplemented, fmt.Errorf("Dot notation is not implemented"))
return nil, NewError(ErrNotImplemented, fmt.Errorf("dot notation for operator %s is not supported yet", op))
}
}

Expand Down

0 comments on commit d03d6a0

Please sign in to comment.