记录的相对陈旧度
我的系统中有投票,但我想根据投票计算和项目的新鲜度进行排序。
我知道在 SQL 中,使用 GETDATE()
、DATEDIFF()
和一些数学魔法来完成这样的事情应该很容易。
我该如何在 Mongo 中做到这一点?需要使用map-reduce吗?我记得听说过 map-reduce 会阻塞 - 所以不建议将其用于高流量的网站页面查询?
谢谢
I have votes in my system, but I want to sort by some calculation of votes and freshness of the item.
I know that in SQL, it should be quite easy to do something like this - with GETDATE()
, DATEDIFF()
and a bit of math magic.
How would I go about doing this in Mongo? Will it require to use map-reduce? I remember hearing that map-reduce is blocking - so it's not recommended for high-traffic website page queries?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 MongoDB 中,您可以对文档中任何字段的值进行排序,但不能对计算值进行排序。
但是,在这种情况下,您不能只按日期(降序)而不是新鲜度排序吗?这不会给出相同的排序顺序吗?
In MongoDB you can sort on the value of any of the fields in a document, but you can't sort on a calculated value.
However, in this case, couldn't you just sort on the date (descending) instead of the freshness? Wouldn't that give the same sort order?