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

Fix :: use $addFields instead of $project in rename and newcolumn steps #75

Merged
merged 2 commits into from Apr 10, 2019

Conversation

vdestraitt
Copy link
Contributor

@vdestraitt vdestraitt commented Apr 9, 2019

This PR aims to replace $project by $addFields whenever possible.

When projecting a given key in a $project in a Mongo aggregation pipeline, you must specify that you project all other keys if you do not want to lose them. Therefore you would need to manipulate metadata to keep track of available columns, and it would generate a lot of noisy code (imagine that you need to add a new column and to keep 20 other ones, you will have a $project with 21 keys, of which 20 just saying <key>: 1...)

$addFields is less verbose, and can be used not only to add a new key but also to modify a key inplace while keeping all other columns. Indeed, specifying an existing field name in an $addFields operation causes the original field to be replaced, while every other columns remain. See Mongo documentation

Copy link
Contributor

@adimascio adimascio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@adimascio adimascio merged commit b6b36e7 into master Apr 10, 2019
@adimascio adimascio deleted the fix/rename-newcolumn-translation branch April 10, 2019 09:47
@vdestraitt vdestraitt mentioned this pull request Apr 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants