Source-to-source compiler for BSON document expressions, converting between shell input and multiple output languages (Java, C#, Node.js, Python, Ruby, Go). Current stable version is 3.3.5. Developed by MongoDB for Compass, it uses ANTLR for parsing. The shell output is disabled and only intended for legacy mongo shell, not mongosh. Python support was removed but remains in an older commit. The library supports both Query and Pipeline modes, and can generate import statements automatically. It is the primary tool for converting MongoDB shell syntax to driver code in different languages, with error codes and line/column details for syntax errors.
npm install bson-transpilersNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage: compile a BSON document from shell to Java, and generate necessary import statements.
Use shell as input only; do not use output language 'shell'. Consider outputting JavaScript (node) for mongosh compatibility.
If you need Python output, use an older version (<=2.x) or reference the removed code at https://github.com/mongodb-js/compass/tree/80cf701e44cd966207f956fac69e8233861b1cd5/packages/bson-transpilers.
Always call getImports with mode ('Query' or 'Pipeline') and driverSyntax (boolean).Ensure input language is lowercase and matches exactly: 'shell', 'javascript' (or 'node'?). Check documentation for supported values.
Run 'npm install bson-transpilers' and ensure you are using require (not import) in CommonJS context.
Check that input is one of 'shell', 'javascript' and output is one of 'java', 'csharp', 'node', 'ruby', 'go'. Do not use 'python' (removed) or 'shell' (deprecated).
Validate the input code string. Use shell-compatible BSON literal syntax, e.g., { field: value } with proper Int32(), ObjectId(), etc.Ensure the package is up to date (npm install bson-transpilers@latest) and that the output language is listed in supported outputs.