Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gobengo/mongo-object-escape
Escape Mongo documents that have '$' or '.' in keys.
https://github.com/gobengo/mongo-object-escape
Last synced: 25 days ago
JSON representation
Escape Mongo documents that have '$' or '.' in keys.
- Host: GitHub
- URL: https://github.com/gobengo/mongo-object-escape
- Owner: gobengo
- License: mit
- Created: 2014-09-11T19:58:03.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2014-12-19T19:53:58.000Z (almost 10 years ago)
- Last Synced: 2024-10-03T15:30:25.049Z (about 1 month ago)
- Language: JavaScript
- Size: 106 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# mongo-object-escape
Mongo cannot store documents that have '$' or '.' in keys.
[The docs](http://docs.mongodb.org/manual/faq/developers/#faq-dollar-sign-escaping) encourage replacing with the Unicode full-width equivalents U+FF04 (i.e. “$”) and U+FF0E (i.e. “.”).
This library escapes and unescapes the keys of an object according to that convention, returning a new object from each.
See [the tests](./test.js) for examples.
## API
```javascript
var mongoObject = require('mongo-object-escape');
var escapedDocToWrite = mongoObject.escape(userInput);
var unescapedDocToRead = mongoObject.unescape(escapedDocToWrite);
```