我正在使用猫鼬一段时间,但我不知道如何使查找结果更容易。我使用快递,当位置是“全部”时我想获得所有结果,而不是位置:“全部”。任何想法的人我怎么能这样做?
Property.find({ 'Location.City': request.params.location }, function(err, allProperties) {
if (err) {
console.log(Date() + " - ERROR Occured: " + err);
}
else {
response.render("propertiesView", { properties: allProperties, propertiesCount: allProperties.length, moment: moment });
}
})
.skip(request.params.page * 10)
.limit(10)
.sort({ PostDate: -1 });
答案 0 :(得分:0)
这可以解决吗?要推送到变量if不等于“ALL”还是另一个变量比这个更容易?
// Set Search settings
var searchSettings = {};
if (request.params.location != "ALL") {
var location = { 'Location.City': request.params.location };
searchSettings.push(location);
}
Property.find(searchSettings, function(err, allProperties) {
if (err) { console.log(Date() + " - ERROR Occured: " + err); }
else {
response.render("propertiesView", { properties: allProperties, propertiesCount: allProperties.length, moment: moment });
}
});