mongodb给所有数据加上某个字段

1,025 阅读1分钟

mongodb,给所有的数据加上一个字段“mark”。需要把multi这个option设为true,才可以批量。

db.getCollection('xxx').update(
    // query 
    {
        //"key" : "value"
    },
    
    // update 
    {
        $set:{"mark":""}
    },
    
    // options 
    {
        "multi" : true,  // update only one document 
        "upsert" : false  // insert a new document, if no existing document match the query 
    }
);