Home
Crypto
Create
Search paradigm has change ... <pre> var filter = { "$and" : [ {"tag.kode_jabatan": req.session.user.kode_jabatan}, {"tag.enable": "1"} ] } if(req.session.search == undefined){ // PASS }else{ for(var a in req.session.search){ if(a !== "hal"){ var value = new RegExp(req.session.search[a], "i") var _subobj = {} _subobj[a] = value filter['$and'].push(_subobj) }else{ var kata = req.session.search[a].split(" ") for(var indexWord in kata){ var value = new RegExp(kata[indexWord], "i") var _subobj = {} _subobj[a] = value filter['$and'].push(_subobj) } } } } </pre> Hasil query mongonya ... <pre> { '$and': [ { 'tag.kode_jabatan': '01' }, { 'tag.enable': '1' }, { nomorAgenda: /(?:)/i }, { tglAgenda: /(?:)/i }, { asal: /(?:)/i }, { nomor: /(?:)/i }, { tanggal: /(?:)/i }, { hal: /cuti/i }, { hal: /asra/i } ] } { '$and': [ { 'tag.kode_jabatan': '01' }, { 'tag.enable': '1' }, { nomorAgenda: /(?:)/i }, { tglAgenda: /(?:)/i }, { asal: /(?:)/i }, { nomor: /(?:)/i }, { tanggal: /(?:)/i }, { hal: /cuti/i }, { hal: /asra/i } ] } </pre> #script #mongodb #project