Closed DeanKamali closed 4 years ago
Does this happened after updating your roles collection from 1.x, or at least you still have the index on the name
field still on your roles
collection?
Yes, it started to happen after the upgrade, I'm not sure what version I had before 1.x or 2.x checking git, it only says alanning:roles
from before.
I only have 3 roles (admin, patient, provider) in roles collection
/** Meteor shell **/
> Roles.getAllRoles().fetch()
[ { _id: 'aWJYaTEjbLzYCJTdu', name: 'admin' },
{ _id: 'owAd3tYj5ZtKWCLTn', name: 'patient' },
{ _id: 'ssYDT95Gcv2xJvKBs', name: 'provider' } ]
> Roles.addUsersToRoles('q5jdXMSiTavQqQkgn', 'admin'); // Trying to add a user to role
Error: Role 'admin' does not exist.
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:-55
at Object.addUsersToRoles (packages/alanning:roles/roles/roles_common.js:372:11)
at Array.forEach (<anonymous>)
at packages/alanning:roles/roles/roles_common.js:379:13
at Array.forEach (<anonymous>)
at packages/alanning:roles/roles/roles_common.js:380:15
at Object._addUserToRole (packages/alanning:roles/roles/roles_common.js:473:15)
>
The roles you show me also are according to the first version of this package. Please run the update script before running any additional commands. First update to v2.0
and then to v3.0
. I advise you to do it in two separate steps as proposed in the readme (https://github.com/Meteor-Community-Packages/meteor-roles#migration-to-30).
Please keep in mind that the update to version 1.x will still leave the old roles in place, which you have to remove manually until https://github.com/Meteor-Community-Packages/meteor-roles/issues/300 is resolved.
Let me know if there's anything else, but this should solve it. Please ask to reopen if it doesn't.
Well, here is what I ended up doing, I dropped roles
and role-assignment
and it got re-created when I added new roles.
Things started to work, however, I faced an issue with getUsersInRole
returning an empty array all the time.
Turned out that my local MongoDB use newer version 4.2 and by downgrading to version 4.0.10
getUsersInRole
method started to work.
Oh! Thanks for notifying! Could you create a new issue for this?
If anyone else comes across the same problem, the sequence of upgrading is important.
meteor remove alanning:roles
and then meteor add alanning:roles@2.0.0
Roles.createRole
. (If you do this step before the migration script you'll get the duplicate error key.)
I'm trying to create a number of new roles and I keep getting this error
alanning:roles@3.1.0
Any ideas?