【发布时间】:2018-06-11 10:55:02
【问题描述】:
我们有一个node.js + mongoose 应用程序在Ubuntu linux 服务器上运行,该服务器在DigitalOcean VPS 上运行。
我们的一个 mongoose 查询有一个 text index 和以下运算符:
看起来像这样:
db.sampleCollection.find({
$text: {
$search: userInput
},
$lte: {
expired: (new Date()).addDays(30)
},
$limit: 9,
$orderby: {
postedAt: -1
}
})
引发此错误:
未知的顶级运算符:$orderby
已经考虑过的解决方案:
- Mongoose uses $set by default,但是我们没有在查询中使用该运算符
- This solution considers aggregation,但是我们需要它来进行查找功能
- This solution seems to be for array fields,但是我们需要非数组索引的解决方案
- 我们不会混合运算符,as said in this solution
需要有关如何解决此问题的意见。
【问题讨论】:
-
@RolandStarke 这个查询无论如何都没有在 mongo shell 上运行,我们的是 MongoDB 服务器版本:
3.4.3 -
你试过
$sort而不是$orderby吗?看看这个解决方案:stackoverflow.com/questions/5825520 它可能会对你有所帮助。 -
@PierreR-A 感谢您的投入,将尽快实施并回复
标签: javascript node.js mongodb mongoose full-text-indexing