Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Projection: excluded and included fields #83

Merged
merged 36 commits into from
Mar 22, 2022
Merged
Changes from 15 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9138d07
test
seeforschauer Mar 9, 2022
6070a4f
to main
seeforschauer Mar 10, 2022
9576b99
elemMatch
seeforschauer Mar 11, 2022
3347523
fix
seeforschauer Mar 14, 2022
330dc84
Merge branch 'main' into issue-257-elemMatch
seeforschauer Mar 14, 2022
17c1b4b
fixing tests
seeforschauer Mar 14, 2022
f28b3f6
filter and elemMatch projection setup
seeforschauer Mar 14, 2022
1c71792
elemaMatch
seeforschauer Mar 14, 2022
32d6fc4
Merge branch 'main' into projection-simple
seeforschauer Mar 21, 2022
cfdf10f
tests for projection
seeforschauer Mar 21, 2022
0514615
wip
seeforschauer Mar 21, 2022
2ae9e87
added err test
seeforschauer Mar 21, 2022
d1b8a55
tests
seeforschauer Mar 22, 2022
49bfed5
lint
seeforschauer Mar 22, 2022
4c47473
lint
seeforschauer Mar 22, 2022
e5838a9
remove v from TestCore/QueryOperators/ProjectionInclusion
seeforschauer Mar 22, 2022
0316ebc
space
seeforschauer Mar 22, 2022
edf6f88
logic
seeforschauer Mar 22, 2022
a1408be
review
seeforschauer Mar 22, 2022
ea77441
space
seeforschauer Mar 22, 2022
ec49c2c
space
seeforschauer Mar 22, 2022
1647170
space
seeforschauer Mar 22, 2022
295720b
error codes added
seeforschauer Mar 22, 2022
88e5f2a
add condition
seeforschauer Mar 22, 2022
0e3ceb0
Update tests/ferret/core_test.go
seeforschauer Mar 22, 2022
c3946a0
Update tests/ferret/core_test.go
seeforschauer Mar 22, 2022
4199915
Update tests/ferret/core_test.go
seeforschauer Mar 22, 2022
5a42aa1
Update tests/ferret/core_test.go
seeforschauer Mar 22, 2022
f05b96f
fix
seeforschauer Mar 22, 2022
6aba2d4
fixees
seeforschauer Mar 22, 2022
46e36af
value is an array
seeforschauer Mar 22, 2022
f430d5f
mongo tests
seeforschauer Mar 22, 2022
4817306
fix
seeforschauer Mar 22, 2022
af15c6b
numbers
seeforschauer Mar 22, 2022
678c7f7
expected pass
seeforschauer Mar 22, 2022
d87d2fc
comment
seeforschauer Mar 22, 2022
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
57 changes: 54 additions & 3 deletions tests/ferret/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func TestCore(t *testing.T) {
var writeErr mongo.BulkWriteException
assert.ErrorAs(t, err, &writeErr)
assert.True(t, writeErr.HasErrorCode(11000))

seeforschauer marked this conversation as resolved.
Show resolved Hide resolved
cursor, err := collection.Find(ctx, bson.D{}, options.Find().SetSort(bson.D{{"_id", 1}}))
require.NoError(t, err)
require.NoError(t, cursor.All(ctx, &docs))
Expand Down Expand Up @@ -153,6 +152,8 @@ func TestCore(t *testing.T) {
testCases := []struct {
name string // TODO move to map key
q bson.D
o *options.FindOptions
seeforschauer marked this conversation as resolved.
Show resolved Hide resolved
v bson.D
AlekSi marked this conversation as resolved.
Show resolved Hide resolved
seeforschauer marked this conversation as resolved.
Show resolved Hide resolved
seeforschauer marked this conversation as resolved.
Show resolved Hide resolved
IDs []string
seeforschauer marked this conversation as resolved.
Show resolved Hide resolved
err error
}{
Expand Down Expand Up @@ -217,6 +218,45 @@ func TestCore(t *testing.T) {
// documents
// TODO

// projection
{
name: "ProjectionInclusion",
q: bson.D{
{"_id", "double"},
},
o: options.Find().SetProjection(bson.D{{"value", int32(11)}}),
v: bson.D{
{"_id", "double"},
{"value", 42.13},
},
IDs: []string{"double"},
},
{
name: "ProjectionExclusion",
q: bson.D{
{"_id", "double"},
},
o: options.Find().SetProjection(bson.D{{"value", false}}),
v: bson.D{
{"_id", "double"},
},
IDs: []string{"double"},
seeforschauer marked this conversation as resolved.
Show resolved Hide resolved
},
{
name: "ProjectionBothError",
q: bson.D{
{"_id", "document-diverse"},
},
o: options.Find().SetProjection(bson.D{
{"document_id", false},
{"array", true},
}),
err: mongo.CommandError{
Code: 2,
Name: "BadValue",
Message: `projection must contain only inclusions or exclusions`,
},
},
// arrays
// $size
{
Expand Down Expand Up @@ -314,7 +354,13 @@ func TestCore(t *testing.T) {
t.Fatal("exactly one of IDs or err must be set")
seeforschauer marked this conversation as resolved.
Show resolved Hide resolved
}

cursor, err := collection.Find(ctx, tc.q, options.Find().SetSort(bson.D{{"value", 1}}))
var cursor *mongo.Cursor
var err error
opts := options.Find().SetSort(bson.D{{"value", 1}})
if tc.o != nil {
opts = tc.o
}
seeforschauer marked this conversation as resolved.
Show resolved Hide resolved
cursor, err = collection.Find(ctx, tc.q, opts)

if tc.err != nil {
require.Error(t, err)
Expand All @@ -326,10 +372,15 @@ func TestCore(t *testing.T) {
require.NotNil(t, cursor)

var expected []bson.D

for _, id := range tc.IDs {
v, ok := data[id]
require.True(t, ok)
expected = append(expected, bson.D{{"_id", id}, {"value", v}})
if tc.v != nil {
expected = append(expected, tc.v)
seeforschauer marked this conversation as resolved.
Show resolved Hide resolved
} else {
expected = append(expected, bson.D{{"_id", id}, {"value", v}})
}
}

var actual []bson.D
Expand Down