KeplerGrid guide

Page through MongoDB results with a stable sort

When several orders share a timestamp, sort by both created_at and _id to give each order a definite position. To continue after a particular row, use both values from that row in the next query.

Break timestamp ties with a unique sort key

Load the 36 synthetic orders. Open keplergrid_query_lab.orders using a Read only connection. In Documents, enter this paid-order filter.

{ "status": "paid" }

Open Sort & projection. Paste this object in Sort, click Run, then choose 25 under Rows.

{ "created_at": -1, "_id": -1 }

MongoDB reads the sort keys in the order shown. It uses _id descending when timestamps tie, giving these practice orders a repeatable order.

Use the page controls in KeplerGrid

At the bottom of the results, the first page is 1–25 and ends at ORD-007. Select Next page, the right arrow. The second page is 26–31 and starts at ORD-006, even though it shares the previous order’s timestamp. Select Previous page to return.

These controls move by a row offset. As orders are inserted, removed or resorted between page reads, document positions can move. The extra sort key resolves ties within each query.

Continue after the last row with a filter

For a query that continues after a specific order, note both values on the last row. ORD-007 has created_at equal to 2026-11-01T12:01:00.000Z. Keep the same sort and replace Filter with the object below. Click Run to start at the first page of this narrower query.

{
  "status": "paid",
  "$or": [
    { "created_at": { "$lt": { "$date": "2026-11-01T12:01:00.000Z" } } },
    {
      "created_at": { "$date": "2026-11-01T12:01:00.000Z" },
      "_id": { "$lt": "ORD-007" }
    }
  ]
}

The results start at ORD-006 and end at ORD-001. The first branch accepts earlier dates. The second accepts orders with the same date and a lower ID. Filtering by earlier dates alone would miss ORD-006 and ORD-005. Use the BSON types and values from the boundary row when adapting the query.

If this is a frequent query, see how to build a MongoDB compound index for a filter and sort.

To reuse a filter and its sort, reopen the query from Query history.