Need help count users in some roles


#1

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.


#2
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.


#3

You were almost there. The field reference was wrong:

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

#4

Thank you very very much… Appreciated…