Local script slowing down while using hosted MongoDB?

Hi,

I recently ran into a problem I can’t figure out, and I would greatly appreciate your help! :slight_smile:

I have a for loop that populates the MongoDB with mock data that uses a random number generator, for test purpose, e.g.:

var mock_data_set = [];
for (var i = 0; i < 10000; i++) {
    mock_data_set.push({
        data_id: data + 'i',
        data_field1: parseInt(Math.random() * 100, 10),
        data_field2: parseInt(Math.random() * 100, 10),
        ...
    });
}

mock_data_set.forEach(function (mock_data) {
    MockDataCollection.insert(mock_data, function() {}); 
});

Now this runs fast when I’m using local MongoDB, but when I use an externally hosted MongoDB (compose.io, via "export MONGO_URL:mongodb:// … "), this becomes incredibly slow (10~20x slower).

What perplexes me is that when I timestamp my operations, what slows down is not the second part that inserts to db, but rather the FOR LOOP that runs LOCALLY!

How can this possibly be? Local javascript that has nothing to do with the external MongoDB slowing down? Has this anything to do with how node.js or meteor generally works?

I’d like to know if anybody knows what is going on here. Thanks in advance!