Lightweight npm package (v2.0.6, last updated 2016) for escaping $ and . characters in MongoDB query keys to prevent NoSQL injection attacks. Replaces $ with Unicode fullwidth dollar sign ($) and . with Unicode fullwidth full stop (.). Only protects against keyword injection, not full JavaScript injection – mapReduce and $where are not safe. Works on strings and objects (keys escaped in-place, no clone). Supports escape and unescape functions, with optional recursion flag. Minimal dependencies, simple API. Suitable for legacy systems needing basic injection prevention; not actively maintained.
npm install mongo-escapeNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic escape and unescape of strings and objects to prevent NoSQL injection by replacing $ and . with fullwidth equivalents.
Disable server-side JavaScript in MongoDB and avoid using mapReduce and $where with untrusted input.
Clone the object before passing to escape if you need to keep the original unescaped.
Ensure input is a string or plain object before calling escape/unescape.
Consider using mongo-sanitize or built-in MongoDB parameterized queries.
Use `const { escape } = require('mongo-escape');` instead of `require('mongo-escape').escape();`Only pass strings or plain objects, not functions or symbols.
Do not use mapReduce or $where with untrusted input; disable server-side JS.
No dependency data recorded yet.