0

I want to do bulk insert for many threads at the same time, each time each thread insert data into different collections. I know it's not thread safe if I put all data into one collection, but what if each thread insert data into a totally different collection? In such case, can I assume it's thread safe and do not have to worry about stuff?

dome some
  • 479
  • 7
  • 22

1 Answers1

2

If every thread uses it's own connection then it is thread safe. There is no difference if you insert in-to the same collection or different ones. The crucial part is that every thread must use it's own separate connection to the database.

Alexey Guseynov
  • 5,116
  • 1
  • 19
  • 29
  • is it possible to allocate bulk operations in one thread, with it's own client, and execute in another thread, the client is only needed at bulk creation moment, not for execution, could it work if I allocate the client from the execution thread ? – user3181125 Oct 23 '21 at 02:12