Skip to content

assertMongoFieldPath

function assertMongoFieldPath(field): string;

Defined in: pagination-mongo.ts:48

Validate a Mongo field path used by the keyset adapter.

Accepts dotted paths such as author.name; rejects $ operators, whitespace, empty segments, and other unsafe field strings. Field mappings must be server-owned and should never come from request data. toMongoKeyset runs every mapped field through it; call it yourself when building other filters from configurable field names.

Parameter Type
field string

string

The same field, unchanged, when valid.

If field is not a dot-separated list of identifiers.

import { assertMongoFieldPath } from "@xtandard/lib/pagination/mongo";
assertMongoFieldPath("author.name"); // "author.name"
assertMongoFieldPath("$where"); // throws: invalid field path "$where"
assertMongoFieldPath("a..b"); // throws: invalid field path "a..b"