mongodb的$inc,递增一个不存在的字段(upsert case)

mongodb's $inc, incrementing a field that does not exists (upsert case)

当您增加一个不存在的字段(upsert case)时会发生什么?...

db.collection.findAndModify({query:{id:"id_in_param"},
                             update:{$inc:{score:1}},
                             upsert:true
                           })

document 表示:

If the field does not exist, $inc creates the field and sets the field to the specified value.

在您的情况下,添加了新字段 score: 1