Parses MongoDB query language strings into an abstract syntax tree (AST) with part-of-speech tagging. Version 2.3.0 is the current stable release, with infrequent updates. Supports strict extended JSON syntax only. Differentiators: provides both acceptance validation and detailed AST generation, designed for use in MongoDB Compass.
npm install mongodb-language-modelNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to use accepts and parse functions for MongoDB query strings.
Ensure query string uses double quotes for keys and strict extended JSON for values.
Evaluate if alternative packages better suit your needs.
Catch errors with (err instanceof pegjs.SyntaxError) or check with accepts() before parsing.
Do not rely on exact AST shape; validate with unit tests after upgrades.
Ensure the query string is a valid JSON object, e.g., '{"key": "value"}'.Use import { accepts } from 'mongodb-language-model' or const { accepts } = require('mongodb-language-model').Follow strict extended JSON format; strings must be quoted, numbers are plain.
Install pegjs: npm install pegjs