Collection updates extremely slow on collection with 300 docs

I’m pretty new to Meteor, so maybe I’m missing something here, but when updating a single document within a collection of 300 docs the callback of the update action takes more than 10 secs…this can’t be right.
However, when only fetching a single doc, the callback of the update action gets called almost immediately :confused:

So here’s what I did:

  • create collection

     Movies = new Meteor.Collection("movies");
    
  • subscribe within the “waitOn” function of the route:

     Meteor.subscribe('movies');
    
  • fetch all documents in a template helper

     return Movies.find();
    
  • as I mentioned, when loading only a single document, the callback is executed really fast

     return Movies.find({_id: '8KnQJAeDX6dWpbgJ4'});
    
  • update one document of the list

     console.log('before update >>', moment().format('HH:mm:ss:SSS'));
     Movies.update({_id: '8KnQJAeDX6dWpbgJ4'}, {$set: {name: 'New name'}}, function(error, result){
         console.log('after update >>', moment().format('HH:mm:ss:SSS'));
     });

Hello,

How did you fix this issue?

Regards

You need to create an index if you haven’t on the _id field for the Movie collection. That should make updates faster.
On your mongo console, do this:

db.movies.createIndex({_id:1}); //though the _id field is automatically indexed on all collections, still do this.

or

Meteor.startup(function () {
  Movies._ensureIndex({some_other_fields: 1}); //some_other_fields could be collection fields you query most like movie_title....
});

That really shouldn’t matter in a case like this. This update ought to only take a few ms, there must be something very wrong here.

This thread began 18 months ago. Perhaps @jpfernandezl would like to open a new thread with the issue he/she has.