通过 db.collection.update ,你可以指定 upsert: true 获得我认为你渴望的行为的选择。如果匹配,它将更新现有记录,否则将创建新记录。
db.collection.update
upsert: true