Need help count users in some roles

Hi all,

I use Alanning Roles with default-group. I have users with the following roles:

  • admin
  • manager
  • appuser

I need to count users in “admin” and “manager” exclude “appuser”.

How to do it correctly? Please advice, thank you.

Meteor.users.find({ "roles": 
    { "default-group": [ "admin"] } 
}).count()

This is the most I can reach. I can’t go any further getting what I need without getting query error.

I tried:

Meteor.users.find({ "roles": 
    { "default-group": { $in: [ "admin", "manager" ] } } 
}).count()

No code error but get zero return. Please advice, thanks.

You were almost there. The field reference was wrong:

Meteor.users.find({ 
  "roles.default-group": { 
    $in: [ "admin", "manager" ], 
    $nin: ["appuser"],
  } 
}).count()
2 Likes

Thank you very very much… Appreciated…