toMongoFilter
function toMongoFilter(input): | MongoFilter | undefined;Defined in: filters/mongo.ts:220
Render an already-compiled CompiledWhere AST (from compileFilters /
compileFilterNode in @xtandard/lib/filters) to a Mongo filter object, looking each field
up in paths. Conditions on fields missing from paths are dropped; null (or an AST that
drops to nothing) gives undefined. and/or/not become $and/$or/$nor. Most code
calls buildFilter, which compiles and renders in one step.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input |
{ paths: Record<string, string>; where: | CompiledWhere | null; } |
input.paths |
Record<string, string> |
input.where |
| CompiledWhere | null |
Returns
Section titled “Returns”| MongoFilter
| undefined
Example
Section titled “Example”import { toMongoFilter } from "@xtandard/lib/filters/mongo";
toMongoFilter({ where: { type: "and", nodes: [ { type: "cond", cond: { field: "amount", op: "gt", value: 5 } }, { type: "cond", cond: { field: "name", op: "isNotNull" } }, ] }, paths: { amount: "amount", name: "name" },});// → { $and: [{ amount: { $gt: 5 } }, { name: { $ne: null } }] }