Meteor-Community-Packages / meteor-roles

Authorization package for Meteor, compatible with built-in accounts packages
http://meteor-community-packages.github.io/meteor-roles/
MIT License
920 stars 164 forks source link

_forwardMigrate2(): user.roles.filter is not a function #306

Closed cormip closed 4 years ago

cormip commented 4 years ago

Attempting to upgrade from version 2 to version 3, I received the following error:

> Package['alanning:roles'].Roles._forwardMigrate2()
TypeError: user.roles.filter is not a function
    at evalCommandPromise.then (packages/shell-server/shell-server.js:249:21)
    at runBound (domain.js:314:12)
    at bound (domain.js:301:14)
    at defaultEval (repl.js:240:29)
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at repl:1:-29
    at Object._forwardMigrate2 (packages/alanning:roles/roles/roles_server.js:298:37)
    at Cursor.(anonymous function) [as forEach] (packages/mongo/mongo_driver.js:887:44)
    at SynchronousCursor.forEach (packages/mongo/mongo_driver.js:1107:16)
    at packages/alanning:roles/roles/roles_server.js:299:18

This was on v3.1.0 I applied all updates and got the same error on v3.2.0

SimonSimCity commented 4 years ago

That means you have a user in your database where the property roles is neither null, nor not existing, and still something but an array ... Can you please check this up? Try to run this command directly on your database (e.g. using Robo 3T):


db.getCollection('users').find({
  roles: {
    $ne: null,
    $not: { $type: "array"  }
  }
})
cormip commented 4 years ago

All of my users have an object as the roles property:

, 
    "roles" : {
        "__global_roles__" : [
            "admin"
        ]
    }

Therefore, I went back and checked, and just realized I was running v1 and not v2. I apologize for my oversight. I'm good to go now.