Skip to content

numberField

const numberField: (input) => MongoFieldSpec;

Defined in: filters/mongo.ts:71

Allow-list a public field as a number filter over a document field path ("total", "stats.views"). between becomes $gte + $lte.

Parameter Type
input { path: string; }
input.path string

MongoFieldSpec

import { buildFilter, numberField } from "@xtandard/lib/filters/mongo";
const { filter } = buildFilter({
spec: { total: numberField({ path: "total" }) },
filters: [{ field: "total", filter: { kind: "number", operator: "between", from: 10, to: 20 } }],
});
// filter → { $and: [{ total: { $gte: 10 } }, { total: { $lte: 20 } }] }