我正在尝试在mongodb $ in
中使用javascript数组它始终用单引号//“室内”,“室外”,“两者”包裹它
我需要它才能工作或喜欢这个 - > “室内”, “室外”, “两者”
url_parts.query.Venue ='Indoor,Outdoor,Both'
var query={};
if(url_parts.query.Venue!= undefined){
var myarr = url_parts.query.Venue.split(",");
var string='';
for (var i = 0; i < myarr.length; i++) {
string+="\""+myarr[i]+"\",";
};
string = string.substring(0, string.length - 1)
query.venues = { $in:[string]};
}
attraction.find(query).lean().exec(function(err, attrs) {....
答案 0 :(得分:2)
正如我所说$in
采用数组:
var url_parts.query.Venue ='Indoor,Outdoor,Both';
var query = {};
query.venues = url_parts.query.Venue.split(",");
所以现在查询看起来像这样:
{ "venues" : { "$in" : [ "Indoor", "Outdoor", "Both" ] } }