Finding and grouping contiguous time windows

I’m considering a data model change, but I’m hitting a roadblock that I’m sure someone else has figured out.

I have two potential data models, both of which I need to find a way to find contiguous time blocks with no more than N seconds between them.

Model A:

    "start":    ISODate("XXXXX"),
    "end":      ISODate("XXXXY")

Model B:

    "time":   ISODate("ZZZZ")

What I want to do, regardless of the model, is find contiguous ‘sessions’ to our dashboard.

In other words, using Model A (denotes the start of a request, and the end of the request fulfillment), group all events that have no more then 5 minutes between the end time of the previous request and the start time of the next, or with Model B (denotes when the request was made), group all requests that had less than 5 minutes between them into a single ‘session’.

I feel like $bucket or $autobucket would apply here, but I guess I’m having a hard time parsing through the docs. Could someone give me an example pipeline that I can cram into a larger pipeline?