MongoDB upsert操作並發的原子性,mongodbupsert

來源:互聯網
上載者:User

MongoDB upsert操作並發的原子性,mongodbupsert

在用C++對MongoDB執行update操作的時候,如果設定了upsert參數為true,則會自動插入不存在的資料。在高並發環境下,會導致資料重複。

解決方案是為查詢條件添加unique index, 參考官方文檔:

http://docs.mongodb.org/manual/core/write-operations-atomicity/

http://docs.mongodb.org/manual/core/index-unique/#index-type-unique


經過高壓測試後,證明這個解決方案是靠譜的。





相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.