0

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?

Sasidhar Vanga
  • 3,384
  • 2
  • 26
  • 47

1 Answers1

0

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

Valijon
  • 12,667
  • 4
  • 34
  • 67
  • Thanks for the answer. But all other users (not administrators) doesn't have a role assigned to them. Basically I have only one role administrator. Will this work in that case? – Sasidhar Vanga May 31 '15 at 05:05
  • Can you give us an input sample to see the document structure? – Valijon Jun 01 '15 at 07:20