Fast on laptop; slow on mlab

Why would the following code take just 5 minutes on my local machine, but over an hour on mlab:

		  $addToSet : {
		    words: word.simplified

p.s. I’m running this both times in MongoChef’s “IntelliShell”. Also, I have the lowest paid plan replica set on mlab.

forEach actually invokes your local mongo shell’s spidermonkey JS engine. Thus, that operation is fetching every matching document from the db and returning it (in batches) to your local MongoChef client. Also, each iteration is blocking on a single update (also incurring a round-trip cost + update time).

I would recommend using the bulk api for these writes (and flushing every 500 - 1000 ops.)