简体   繁体   中英

Parse.com : Fetch all users with no role assigned

I have some users in which some of the users have administrator role assigned to them. All other users doesn't have a role assigned to them.

I am able to fetch only users who have administrator role assigned to them using the following code.

var query = new Parse.Query(Parse.Role);
query.equalTo("name", "administrator");
query.first({
    success : function(role) {
        var relation = role.getUsers();
        relation.query().find({
            success : function(results) {
                console.log(results);
            },
            error : function(error) {
                console.log(error);
            }
        });
    },
    error : function(error) {
        console.log(error);
    }
});

How can I fetch users to whom any role is not assigned?

Try Parse.Query.notEqualTo :

var query = new Parse.Query(Parse.Role);
query.notEqualTo("name", "administrator");
query.first({
    success : function(role) {
        var relation = role.getUsers();
        relation.query().find({
            success : function(results) {
                console.log(results);
            },
            error : function(error) {
                console.log(error);
            }
        });
    },
    error : function(error) {
        console.log(error);
    }
});

Also, maybe these filters may help you

query.doesNotExist("name");
query.notContainedIn("role", ["Administrator"]);

https://parse.com/docs/js/guide#queries-query-constraints

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM