Database

[{order:1,state:"one"},{order:2,state:"one"},{order:3,state:"one"},{order:4,state:"two"},{order:5,state:"two"},{order:6,state:"one"},{order:7,state:"two"},{order:8,state:"three"},{order:9,state:"three"}]

Query

db.collection.aggregate([{$sort:{order:1}},{$group:{_id:null,docs:{$push:"$$ROOT"}}},{$set:{docs:{$reduce:{input:"$docs",initialValue:[],in:{$cond:{if:{/** last value `state` is different or initial value*/$ne:[{$getField:{field:"state",input:{$last:{$last:"$$value"}}}},"$$this.state"]},then:{$concatArrays:["$$value",[["$$this"]]]},else:{$concatArrays:[/** take all except the last elements of the current*/{$slice:["$$value",{$subtract:[{$size:"$$value"},1]}]},/** add this element to the last subarray* and concat it to the previous*/[{$concatArrays:[{$last:"$$value"},["$$this"]]}]]}}}}}}},{/** if you want all the groups in one result, remove this stage*/$unwind:"$docs"}])

Result