-
Notifications
You must be signed in to change notification settings - Fork 378
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: <field>: <1 or true>
and <field>: <0 or false>
#377
Changes from 10 commits
9101afa
ae262c1
69ab62c
544bbfd
b6643c4
3bd4edd
fd8a27f
92c4994
9d2ae05
3a899c1
4dd9957
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
/bin/ | ||
/vendor/ | ||
cover.txt | ||
cover.html | ||
old.txt | ||
new.txt | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,10 +14,47 @@ | |
|
||
package common | ||
|
||
import "github.com/FerretDB/FerretDB/internal/types" | ||
import ( | ||
"github.com/FerretDB/FerretDB/internal/types" | ||
"github.com/FerretDB/FerretDB/internal/util/lazyerrors" | ||
) | ||
|
||
// ProjectDocuments modifies given documents in places according to the given projection. | ||
func ProjectDocuments(docs []*types.Document, projection *types.Document) error { | ||
// TODO | ||
if projection.Len() == 0 { | ||
return nil | ||
} | ||
projectionMap := projection.Map() | ||
for i := 0; i < len(docs); i++ { | ||
for k := range docs[i].Map() { | ||
if k == "_id" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. _id handing is more complicated than that |
||
continue | ||
} | ||
|
||
v, ok := projectionMap[k] | ||
if !ok { | ||
docs[i].Remove(k) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have a dance test for that? It is not clear from documentation how MongoDB behaves there There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, dance has no tests for it at all, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure |
||
continue | ||
} | ||
|
||
switch v := v.(type) { | ||
case bool: | ||
if !v { | ||
docs[i].Remove(k) | ||
continue | ||
} | ||
continue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need both those |
||
|
||
case int32, int64, float32, float64: | ||
seeforschauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if compareScalars(v, int32(0)) == equal { | ||
AlekSi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
docs[i].Remove(k) | ||
continue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed |
||
} | ||
default: | ||
return lazyerrors.Errorf("unsupported operation {%v %v}", k, v) | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it can be done w/o creation of new variable..