Search code examples
multithreadingmongodbparallel-processingmongo-c-driver

thread safe for different collections in mongo_c_driver


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?


Solution

  • 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.