Convert a Filter to a MongoDB Query

Use @odata-filter/marshalers to transform a parsed AST into a MongoDB-compatible query object.

npm i @odata-filter/core @odata-filter/marshalers --save
import { tokenize, parse } from '@odata-filter/core';
import { toMongoJson } from '@odata-filter/marshalers';

const ast = parse(tokenize("country/name eq 'US' and age gte 21"));

console.log(toMongoJson(ast));
/*
{
  "$and": [
    { "country/name": { "$eq": "US" } },
    { "age": { "$gte": 21 } }
  ]
}
*/

Copyright © 2026 The OData Filter Authors.