def user_roles_exists(name, roles, database, user=None, password=None, host=None, port=None, authdb=None):
 try:
  roles = _to_dict(roles)
 except Exception:
  return 'Roles provided in wrong format'
 users = user_list(user, password, host, port, database, authdb)
 if isinstance(users, string_types):
  return 'Failed to connect to mongo database'
 for user in users:
  if (name == dict(user).get('user')):
   for role in roles:
    if (not isinstance(role, dict)):
     role = {'role': role, 'db': database}
    if (role not in dict(user).get('roles', [])):
     return False
   return True
 return False

def user_roles_exists ( name , roles , database , user = None , password = None , host = None , port = None , authdb = None ) : try : roles = _to_dict ( roles ) except Exception : return 'Roles provided in wrong format' users = user_list ( user , password , host , port , database , authdb ) if isinstance ( users , string_types ) : return 'Failed to connect to mongo database' for user in users : if ( name == dict ( user ) . get ( 'user' ) ) : for role in roles : if ( not isinstance ( role , dict ) ) : role = { 'role' : role , 'db' : database } if ( role not in dict ( user ) . get ( 'roles' , [ ] ) ) : return False return True return False
checks if a user of a mongodb database has specified roles cli examples: .