percolatestudio/meteor-migrations

TypeError: Object [object Object] has no method 'forEach'

laran opened this issue · 1 comments

I followed the pattern that you used in the examples folder.

I have a migrations.js file in /server.

It's structured like this:

if(Meteor.isServer) {
  Migrations.add({
    version: 1,
    name: 'Replace username column on tasks with userId',
    up: function() {
      Tasks.forEach(function(task){
        Tasks.update({_id: task._id}, {$set: {
          ...
        }});
      });
    },
    down: function() {
      Tasks.forEach(function(task){
        Tasks.update({_id: task._id}, {$set: {
          ...
        }});
        Tasks.update({_id: task._id}, {$unset: {
          ...
        }});
      });
    }
  });

  // Add other migrations above here.

  Meteor.startup(function(){
    Migrations.migrateTo('latest');
  });

}

The problem is that every time I restart my server I get the following error:

[abc] /opt/foo/app/programs/server/node_modules/fibers/future.js:173
                        throw(ex);
                              ^
TypeError: Object [object Object] has no method 'forEach'
    at Migrations.add.up (app/server/migrations.js:6:13)
    at migrate (packages/percolate:migrations/migrations_server.js:142:1)
[104.236.142.118]     at Object.Migrations._migrateTo (packages/percolate:migrations/migrations_server.js:153:1)
    at Object.Migrations.migrateTo (packages/percolate:migrations/migrations_server.js:80:1)
    at app/server/migrations.js:30:16
    at /opt/foo/app/programs/server/boot.js:212:5
error: Forever detected script exited with code: 8
error: Script restart attempt #1
[104.236.142.118] Not migrating, control is locked.[104.236.142.118]

It's blowing up on calling Tasks.forEach.

I tried naming the file main.migrations.js in order to get it to load after everything else. But it didn't make a difference.

Did I define something wrong in my migration? Or am I calling it wrong in startup? Something else maybe?

zol commented

Tasks is a collection not a cursor. I think you meant something like Tasks.find().forEach(...)