【发布时间】:2014-05-28 08:06:38
【问题描述】:
我正在使用 Mongoose.js 与我的 Mongo 数据库进行交互。此函数搜索我的Location 名称,并且应该将not found 记录到控制台而不是found,因为我没有名称为!@£ 的Location。
Location.find({name: "!@£"}, function(err, obj) {
console.log(obj);
if (!err) {
console.log("found");
} else {
console.log("not found");
}
});
这是退出我的控制台的内容:
[]
found
预期的行为应该是将not found 记录到控制台。这是Location 模型数据的转储:
[
{
"_id":"5384c421af3de75252522aa2",
"name":"London, UK",
"lat":51.508515,
"lng":-0.12548719999995228,
"__v":0,
"modified":"2014-05-27T16:58:09.546Z",
"search_count":1
},
{
"_id":"5384c766af3de75252522ab4",
"name":"Paris, France",
"lat":48.856614,
"lng":2.3522219000000177,
"__v":0,
"modified":"2014-05-27T17:12:06.990Z",
"search_count":1
},
{
"_id":"53851a213a33fe392b758046",
"name":"Zagreb, Croatia",
"lat":45.8150108,
"lng":15.981919000000062,
"__v":0,
"modified":"2014-05-27T23:05:05.306Z",
"search_count":1
}
]
【问题讨论】: