mongodb error - MongoServerSelectionError: Server selection timed out after 30000 ms

Viewed 41

I'm a new user with mongodb and i have a node application that once in sometime(30 min) reads and parse a folder with ~3000 json files then insert relevant data to the db.

I implemented this function as a foreach with one insert call every time.

The error i got:

MongoServerSelectionError: Server selection timed out after 30000 ms

A workaround: When i limit the insert operation to only 2 files it works fine.

So looks like the issue is because i run many insert commands togather. The question is :

  1. Is this behavior is make sense?
  2. In this case it's batter option to replace the function to use insertMany instead of singel insert?
  3. Is there a way to use the insertMany to add only new objects there are still not exists?

Thanks.

0 Answers
Related