mongodb: should i always use the 'safe' option on updates

后端 未结 3 1154
名媛妹妹
名媛妹妹 2021-02-08 11:03

when dealing with mongodb, when should i use the {safe: true} on queries?

Right now I use the \'safe\' option just to check if my queries were inserted or updated succes

3条回答
  •  伪装坚强ぢ
    2021-02-08 11:34

    Assuming when you say queries you actually mean writes/inserts (the wording of your question makes me think this) then the Write Concern (safe, none, fsync, etc) can be used to get more speed and less safety when that is acceptable, and less speed and more safety when that is necessary.

    As an example, a hypothetical Facebook-style application could use an unsafe write for "Likes" while it would use a very safe write for password changes. The logic behind this is that there will be many thousand "Like"-style updates happening a second, and it doesn't matter if one is lost, whereas password updates happen less regularly but it is essential that they succeed.

    Therefore, try to tailor your Write Concern choice to the kind of update you are doing, based upon your speed and data integrity requirements.

提交回复
热议问题