Mongodb count the number of consecutive matching docs and merge them into one

Thanks for the response. Can you please give an example of what the 2 buckets would look like? I’m not sure if the regular one is supposed to contain the grouping or if you mean that it contains the messages in their normal order.