Parse query not restricting results to current user

Using and the JS SDK.

Why wouldn't this query restrict the results to the current user only? I've used

query.exists("ProfilePic"), Parse.User.current();

which i thought would do this, but all of my users profile images are being returned in the second part of the query, meaning I have the wrong profile picture for the current user.

Not sure why this is?

var query = new Parse.Query(Parse.User);
var user = Parse.User.current();
if( user.has("ProfilePic") )
        success: function(results) {
            // If the query is successful, store each image URL in an array of image URL's
            imageURLs = [];
            for (var i = 0; i < results.length; i++) {
                var object = results[i];
            // If the imageURLs array has items in it, set the src of an IMG element to the first URL in the array
            if (imageURLs.length > 0) {
                $('#Image01').attr('src', imageURLs[0]);
                $('#Image01').attr('src', imageURLs[0]); //first image
        error: function(error) {
            // If the query is unsuccessful, report any errors
            alert("Error: " + error.code + " " + error.message);



You're not using query.exists() the way you think you are. Also, are you just trying to check to see if the current user has a profile image? Because you can just use the .has("key") method of objects, and a user is an object. If this is in cloud code, rather than client code, you may have to fetch the user first. If it is client code, you should already have an up to date user.

You should not be extending the user object. Not necessary at all. Use the Parse.User object type, so if you're querying for users, do var query = new Parse.Query( Parse.User );

So I think what you want is something more like:

var user = Parse.User.current();
if( user.has("ProfilePic") )
    //Do your stuff with the image
    var imageURL = user.get("ProfilePic").url();
    $('#Image01').attr('src', imageURL);
    alert("Error: User does not have a 'ProfilePic' set");


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.