Mongodb upsert增量

时间:2018-07-30 13:50:24

标签: mongodb upsert

如果不存在(具有默认值),我想更新或插入活动:

我的JSON:

{"item" : 
    {"id":"031", 
    "activity": 
        [{"code":"1", "name": "activityA", "compt":"1"}
        {"code":"2", "name": "activityB", "compt":"0"}]
    }

类似的东西……

 db.items.update({id:"id_in_param"},{activity.code:"code_in_param",activity.name:"name_in_param", $inc:{activity.compt:1}, $setOnInsert:{activity.compt:1}}, {upsert:true});

0 个答案:

没有答案