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

Extract operations logic #49

Open
fcoury opened this issue Aug 4, 2022 · 0 comments
Open

Extract operations logic #49

fcoury opened this issue Aug 4, 2022 · 0 comments
Labels
enhancement New feature or request refactor

Comments

@fcoury
Copy link
Owner

fcoury commented Aug 4, 2022

Operations like $multiply are confined to the stage it's coded on ($group in this case).

We should extract all operations and allow them to be called from many different places, like on $project phase.

One example from MongoDB with our orders collection:

test> db.orders.aggregate([{ $project: { array: [ '$name', { $multiply: [ '$price', '$quantity'] }] } }])
[
  { _id: 0, array: [ 'Pepperoni', 190 ] },
  { _id: 1, array: [ 'Pepperoni', 400 ] },
  { _id: 2, array: [ 'Pepperoni', 630 ] },
  { _id: 3, array: [ 'Cheese', 180 ] },
  { _id: 4, array: [ 'Cheese', 650 ] },
  { _id: 5, array: [ 'Cheese', 140 ] },
  { _id: 6, array: [ 'Vegan', 170 ] },
  { _id: 7, array: [ 'Vegan', 180 ] }
]

And the data:

db.orders.insertMany([ { name: "Pepperoni", size: "small", price: 19, quantity: 10, date: ISODate("2021-03-13T08:14:30Z") }, { name: "Pepperoni", size: "medium", price: 20, quantity: 20, date: ISODate("2021-03-13T09:13:24Z") }, { name: "Pepperoni", size: "large", price: 21, quantity: 30, date: ISODate("2021-03-17T09:22:12Z") }, { name: "Cheese", size: "small", price: 12, quantity: 15, date: ISODate("2021-03-13T11:21:39.736Z") }, { name: "Cheese", size: "medium", price: 13, quantity: 50, date: ISODate("2022-01-12T21:23:13.331Z") }, { name: "Cheese", size: "large", price: 14, quantity: 10, date: ISODate("2022-01-12T05:08:13Z") }, { name: "Vegan", size: "small", price: 17, quantity: 10, date: ISODate("2021-01-13T05:08:13Z") }, { name: "Vegan", size: "medium", price: 18, quantity: 10, date: ISODate("2021-01-13T05:10:13Z") }]);
@fcoury fcoury added enhancement New feature or request refactor labels Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactor
Projects
None yet
Development

No branches or pull requests

1 participant