我们有MongoDB Mongoose查询:
sampleSchema.find({
$where: "expired <= " + (new Date())
})
.limit(9)
.sort({
postedDate: -1
})
.then((docs) => {
console.log('found docs ', docs);
})
.catch((err) => {
console.log('error ', err);
})
此查询始终转到catch
块,抛出的错误为:
{
"name": "MongoError",
"message": "Failed to call method",
"ok": 0,
"errmsg": "Failed to call method",
"code": 1,
"codeName": "InternalError"
}
此查询有什么问题?
答案 0 :(得分:0)
分享给未来的读者
这可以解决问题:
{expire: {$lte : (new Date())}