MongoDB文本搜索和排序 [英] MongoDB text search and order by
本文介绍了MongoDB文本搜索和排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们正在使用MongoDB的文本搜索,到目前为止效果很好.但是,我们还要指定结果的顺序,例如:
We're using MongoDB's text search, which so far is working great. However, we want to also specify an order for the results, such as this:
db.items.runCommand("text", {search: "\"test item\"", "$orderby" : { votes : 1 }});
这会执行,但不会按票数排序,仍然按比分排序.
This executes, but it doesn't sort by votes, it's still ordered by the score.
有人知道怎么做吗?
谢谢!
推荐答案
MongoDB的"text"
命令不支持自定义排序,因此您必须在自己的代码中按votes
对结果进行排序.
MongoDB's "text"
command doesn't support custom sorting so you'd have to sort the results by votes
in your own code.
此处中列出.
这篇关于MongoDB文本搜索和排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文