📌  相关文章
📜  mongodb 添加新字段 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:33.661000             🧑  作者: Mango

代码示例2
// If you want to add a new_field to all your collection, you have to use empty
// selector, and set multi flag to true (last param) to update all the documents

db.your_collection.update(
  {},
  { $set: {"new_field": 1} },
  false,
  true
)
// In the above example last 2 fields false, true specifies the upsert and multi flags.
// Upsert: If set to true, creates a new document when no document matches the query criteria.