Best Practice for inserting thousands of documents into the DB

I am trying to insert 18,000+ documents into the Mongo DB. Seems to be successful except I have to refresh the page afterwards because it responds very slowly.
Right now I handle the insertion by looping through the items and inserting one at a time. I have no pub/subs for this large collection at the current moment, I am going to handle that next.
But was just wondering if there are any precautions I should take to ensure the insertion is successful and my app does not crash. Or if there is a recommended way to handle this.
My second time running this insert my app never gave me my Error/Success messages which was a little worrying.

You should probably read the blog post about inserting 50K docs and possibly also try out mikowals:batch-insert

Beware of your subscriptions, though. Instant spikes in mass inserts/updates may choke your server and you may need to work around oplog tailing.

1 Like

Good read, thank you.