mongodb中的条件更新 [英] conditional update in mongodb

查看:433
本文介绍了mongodb中的条件更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面有以下架构,需要进行更新,下面将对此进行详细说明.不知道如何去做.

I have the following schema below and need do an update which is detailed below. Not sure how to go about it.

UserPromo = new Schema
  sendFBInvite:
    earnedIntros:
      type: Number
      default: 0
    earningActionCounter:
      type: Number
      default: 0
    actions:
      type: Number
      default:1
  earnings:
    earnedIntros:
      type: Number
      default: 0
    usedIntros:
      type: Number
      default: 0

每次sendFBInvite.earningActionCounter转到5我想让sendFBInvite.earnedIntros增加 和gain.earnedIntros递增1.同时,我想将sendFBInvite.earningActionCounter重置为0

everytime sendFBInvite.earningActionCounter goes to 5 I want sendFBInvite.earnedIntros to increment and earnings.earnedIntros to increment by 1. At the same time I want to reset sendFBInvite.earningActionCounter to 0

有没有办法在一个电话中做到这一点?预先感谢您的帮助!

Is there a way to do this in one call? thanks in advance for your help!

推荐答案

否. MongoDB的核心是在应用程序级别而不是DB中拥有所有业务逻辑.简而言之,我认为这是不可能的.

NO. The core of MongoDB is to have all the business logic in the application level and not DB. So in short I don't think its possible.

旁注: MongoDB非常快,您可以运行多个选择/查找查询,然后启动和更新.另外,还有findAndModify命令( http://docs.mongodb.org/manual/reference /command/findAndModify/),这可能对您有所帮助.

Side note: MongoDB is very fast and you can run multiple select/ find queries and then fire and update. Plus there is also findAndModify command (http://docs.mongodb.org/manual/reference/command/findAndModify/) by which might be good for you to look into.

这篇关于mongodb中的条件更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆