How do I update MongoDB document fields only if they don't exist?

后端 未结 6 828
春和景丽
春和景丽 2020-12-08 09:03

I have collection foo with documents like:

{site_id: \'xxx\', title: {ru: \'a\', en: \'b\'}, content:         


        
6条回答
  •  离开以前
    2020-12-08 10:09

    there is a update field operator $setOnInsert which meets your requirement. Please read the documents here: https://docs.mongodb.com/manual/reference/operator/update/setOnInsert/#up._S_setOnInsert

提交回复
热议问题