mongo-query-builder
v0.0.2
Published
A simple function which takes a json object and converts it to a mongo query string
Downloads
2
Readme
#MongoQueryBuilder
This module consists on a method which accepts a json object and converts it to a mongo query string
##Instalation
npm install mongo-query-builder
##Usage
es6:
import QueryBuilder from 'mongo-query-builder'
let json = {
prop1: 'oi',
prop2: {
g1: 29,
g2: 30,
g25: null,
g3: {
mais: {
more: 'plus',
mas: 'errado'
}
}
},
prop3: 'olá',
prop4: 'tchau',
prop5: {
a: 1,
b: 2,
c: {
da: 4,
de: 5,
di: ''
}
},
prop6: {
$gte: 2007,
$lte: 2015,
},
prop7: undefined
}
let query = QueryBuilder(json)
//`{%22prop1%22:%22oi%22,%22prop2.g1%22:29,%22prop2.g2%22:30,%22prop2.g3.mais.more%22:%22plus%22,%22prop2.g3.mais.mas%22:%22errado%22,%22prop3%22:%22olá%22,%22prop4%22:%22tchau%22,%22prop5.a%22:1,%22prop5.b%22:2,%22prop5.c.da%22:4,%22prop5.c.de%22:5,%22prop6%22:{%22$gte%22:2007,%22$lte%22:2015}}`
es5:
const QueryBuilder = require('mongo-querybuilder')
let json = {
prop1: 'oi',
prop2: {
g1: 29,
g2: 30,
g25: null,
g3: {
mais: {
more: 'plus',
mas: 'errado'
}
}
},
prop3: 'olá',
prop4: 'tchau',
prop5: {
a: 1,
b: 2,
c: {
da: 4,
de: 5,
di: ''
}
},
prop6: {
$gte: 2007,
$lte: 2015,
},
prop7: undefined
}
let query = QueryBuilder(json)
//`{%22prop1%22:%22oi%22,%22prop2.g1%22:29,%22prop2.g2%22:30,%22prop2.g3.mais.more%22:%22plus%22,%22prop2.g3.mais.mas%22:%22errado%22,%22prop3%22:%22olá%22,%22prop4%22:%22tchau%22,%22prop5.a%22:1,%22prop5.b%22:2,%22prop5.c.da%22:4,%22prop5.c.de%22:5,%22prop6%22:{%22$gte%22:2007,%22$lte%22:2015}}`