$bucket vs $group

Can we generate result of $bucket using $group?
If yes, What is difference of $bucket and $group? When to use which one? Is there any real example

Yes you could but with some effort. You would need some complicated $addFields to define the buckets. But why would you want to complicate your life by using a stage meant for a different purpose.

The main difference is that $group will produce 1 document for each value you $group on while $bucket will produce 1 document per bucket. Look at the artists example of $bucket. If you would use _id:$year_born in a $group you would end up with 1 document for each unique value of year_born rather than 1 document per year range.

You could think that $group is per value and $bucket is per value range.

1 Like

Dear @Prof_Monika_Shah,

please followup on this thread and your other one at

Marking one post as the solution will provide confidence to the other users that it makes sense as they might have the same questioning.

Followup questions for clarification is also a good way to keep the forum useful.