My data has an array in which each object contains state and I need to filter from that value.
I have my data as follows,
"npi" : [
{
"npi" : "1013987536",
"xm_score" : 70.3,
"state" : "TX",
"zip" : "78026",
"lat" : 28.918592,
"lon" : -98.54152,
"specialty" : [
"x065",
"x109"
]
},
{
"npi" : "1023010527",
"xm_score" : 70.0,
"state" : "MA",
"zip" : "02120",
"lat" : 42.32918979,
"lon" : -71.10625722,
"specialty" : [
"x065",
"x109"
]
},
{
"npi" : "1033116371",
"xm_score" : 70.9,
"state" : "TN",
"zip" : "37207",
"lat" : 36.222188,
"lon" : -86.773002,
"specialty" : [
"x067"
]
},
{
"npi" : "1053435198",
"xm_score" : 71.0,
"state" : "KS",
"zip" : "66160",
"lat" : 39.05615308,
"lon" : -94.61062748,
"specialty" : [
"x096",
"x067"
]
}]
I need to searh for the states,
var modelObj = {'npi': []};
if (state) {
modelObj.npi.state = state;
}
match.find(modelObj).limit(10).exec(function(err,data) {
callback(null, data);
});
This is what i tried but this really didnt worked for me.an anyone please suggest me help.Thanks.