KeplerGrid guide

Count documents matching a MongoDB filter across every page

Count documents asks MongoDB how many documents match the current filter. The results toolbar shows how many documents KeplerGrid loaded for the current page, and Find in results searches that page.

Set up 36 practice orders

Run this once in mongosh against a development instance with an empty practice collection. It creates 31 paid orders and five cancelled orders. The same data works for the stable pagination guide.

const lab = db.getSiblingDB("keplergrid_query_lab")
lab.orders.insertMany(Array.from({ length: 36 }, (_, index) => {
  const number = index + 1
  const minute = Math.floor((number + 3) / 8)
  return {
    _id: "ORD-" + String(number).padStart(3, "0"),
    status: number <= 31 ? "paid" : "cancelled",
    created_at: new Date(Date.UTC(2026, 10, 1, 12, minute))
  }
}))

Get the exact filter count

  1. Connect in Read only mode and open keplergrid_query_lab.orders in Documents. Paste this object into Filter.
{ "status": "paid" }
  1. Open Sort & projection and paste the following object into Sort. Click Run and set Rows to 25 in the footer.
{ "created_at": -1, "_id": -1 }
  1. Click Count documents in the footer. It shows 31 matches, even though the result page holds 25 documents.

The count applies the server-side filter across the collection. Sorting, projection and page size leave that count unchanged. Use Count again to refresh the number after another client changes the data.

Next, Find distinct MongoDB values and count their documents.