[英]MongoDB update a mean
I am trying to cache a mean order to avoid retrieving all ratings and avoid aggreagtion (since the mean is to be obtained often): This is basically what I would do: 我正在尝试缓存均值顺序,以避免检索所有评分并避免积聚(因为通常会经常获得均值):这基本上是我会做的事情:
Product.findOne _id: id, (prod) ->
prod.mean = (prod.rate_count * prod.mean + rateCasted) / (prod.rating_count + 1)
prod.rate_count++
prod.save()
Problem: this implies loading the Product into the app, which I don't wanna do (performance, concurrent vote casting...) 问题:这意味着将产品加载到应用中,而我不想这么做(性能,并发投票...)
So how do I do it with a single update
operation? 那么,如何通过一次
update
操作呢?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.