Mongo dot-notation tool
Convert dot-notation to simple JS object and back.
Install
npm install mongo-dot-notation-tool --save
Use
var dotNotationTool = ;
Methods
encode
Convert JS object to mongo dot-notation object
Use
dotNotationTool;// returns: {'name.last': 'Foo', 'name.first': 'Bar'} dotNotationTool;// returns: {$and: [{'name.last': 'Foo'}, {position: 'CTO'}]} dotNotationTool;/*returns: { $and: [ { $or: [ { 'name.last': 'Foo' }, { 'name.last': 'Bar' } ], position: 'CTO' ] }}*/
decode
Convert mongo dot-notation object to JS object
Use
dotNotationTool;// returns: {name: {last: 'Foo', first: 'Bar'}} dotNotationTool;// returns: {$and: [{name: {last: 'Foo'}}, {position: 'CTO'}]} dotNotationTool;/*returns: { $and: [ { $or: [ { name: { last: 'Foo' } }, { name: { last: 'Bar' } } ], position: 'CTO' ] }}*/
Run tests
npm test# or npm i./node_modules/.bin/mocha ./test.js# or npm i -g mochamocha ./test.js