dateField
const dateField: (input) => MongoFieldSpec;Defined in: filters/mongo.ts:38
Allow-list a public field as a date filter over a document field path ("createdAt",
dot paths allowed) holding a Date. A date preset needs the resolveDate you pass to
buildFilter, and becomes a half-open $gte/$lt window.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input |
{ path: string; } |
input.path |
string |
Returns
Section titled “Returns”Example
Section titled “Example”import { buildFilter, dateField } from "@xtandard/lib/filters/mongo";
// Your resolver turns the preset into instant bounds (this one is hard-coded).const resolveDate = () => ({ start: new Date("2026-01-01T00:00:00Z"), end: new Date("2026-02-01T00:00:00Z") });const { filter } = buildFilter({ spec: { createdAt: dateField({ path: "createdAt" }) }, filters: [{ field: "createdAt", filter: { kind: "date", operator: "is", unit: "month", timeZone: "UTC", anchor: "2026-01-15T00:00:00" } }], resolveDate,});// filter → { $and: [// { createdAt: { $gte: new Date("2026-01-01T00:00:00Z") } },// { createdAt: { $lt: new Date("2026-02-01T00:00:00Z") } },// ] }