How to improve MongoDB insert performance

前端 未结 4 460
粉色の甜心
粉色の甜心 2020-12-24 13:00

The result:

If you are operating on a dataset that is fault tolerant, or doing a one time process you can verify, changing WriteAcknowledge

4条回答
  •  死守一世寂寞
    2020-12-24 13:32

    You can try to modify the Write concern levels. Obviously there is a risk on this, as you wouldn't be able to catch any writing error, but at least you should still be able to capture network errors. As MongoDB groups the bulk insert operations in groups of 1000, this should speed up the process.

    W by default is 1:

    enter image description here

    When you change it to 0:

    enter image description here

    If you are not concern about the order of elements, you can gain some speed calling the unordered bulk operation

    await m_Collection.BulkWriteAsync(updates, new BulkWriteOptions() { IsOrdered = false });
    

    With an unordered operations list, MongoDB can execute in parallel the write operations in the list and in any order. Link

提交回复
热议问题