在 Mongodb 中,如何首先按分数排序,然后如果存在“平局”则按时间排序?
results = docDB.posts.find({"active":True }).sort("pop_score", pymongo.DESCENDING)
我现在就是这样的。但问题是,有些东西的“分数”是相同的。在这种情况下,如果他们打平,我希望他们在打平的人中按“时间”排序。
我该怎么做?在Mysql中可以做到这一点...
results = docDB.posts.find({"active":True }).sort("pop_score", pymongo.DESCENDING)
This is my sort right now. But the problem is, some things have the same "score". In that case, if they tie, I want them to sort by "time" within the ones who tied.
How do I do that? It's possible to do that in Mysql...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您一次可以按多个属性进行排序。例如,
将按姓名升序排序,然后按年龄降序排序
,请参见此处:http: //www.mongodb.org/display/DOCS/Sorting+and+Natural+Order
编辑:
在 pymongo 中,这将是
引用L http://api.mongodb.org/python/current/api/pymongo/cursor.html#pymongo.cursor.Cursor .排序
You can sort by more than one attribute at a time. e.g.
will sort by name ascending then by age descending
See here for reference: http://www.mongodb.org/display/DOCS/Sorting+and+Natural+Order
Edit:
In pymongo, that would be
referenceL http://api.mongodb.org/python/current/api/pymongo/cursor.html#pymongo.cursor.Cursor.sort