Thu, 6 Nov 2014 2:02 pm
Search paradigm has change ...
	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)
				}
			}
		}
	}
Hasil query mongonya ...
{ '$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 } ] }
#script #mongodb #project
168
Additional Info: