mongo-dot-notation-tool
v1.0.1
Published
Tool for mongo dot-notation objects
Downloads
243
Readme
Mongo dot-notation tool
Convert dot-notation to simple JS object and back.
Install
npm install mongo-dot-notation-tool --save
Use
var dotNotationTool = require('mongo-dot-notation-tool');
Methods
encode
Convert JS object to mongo dot-notation object
Use
dotNotationTool.encode({name: {last: 'Foo', first: 'Bar'}});
// returns: {'name.last': 'Foo', 'name.first': 'Bar'}
dotNotationTool.encode({$and: [{name: {last: 'Foo'}}, {position: 'CTO'}]});
// returns: {$and: [{'name.last': 'Foo'}, {position: 'CTO'}]}
dotNotationTool.encode({
$and: [
{
$or: [
{
name: {
last: 'Foo'
}
},
{
name: {
last: 'Bar'
}
}
],
position: 'CTO'
]
}
});
/*
returns: {
$and: [
{
$or: [
{
'name.last': 'Foo'
},
{
'name.last': 'Bar'
}
],
position: 'CTO'
]
}
}
*/
decode
Convert mongo dot-notation object to JS object
Use
dotNotationTool.decode({'name.last': 'Foo', 'name.first': 'Bar'});
// returns: {name: {last: 'Foo', first: 'Bar'}}
dotNotationTool.decode({$and: [{'name.last': 'Foo'}, {position: 'CTO'}]});
// returns: {$and: [{name: {last: 'Foo'}}, {position: 'CTO'}]}
dotNotationTool.decode({
$and: [
{
$or: [
{
'name.last': 'Foo'
},
{
'name.last': 'Bar'
}
],
position: 'CTO'
]
}
});
/*
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 mocha
mocha ./test.js