0

I would like to know why could you get this error:

Error code: 102, error message: $in requires an array

I'm using Parse JavaScript SDK.

The data structure it this one:

enter image description here

The source code of the function is this one:

Parse.Cloud.define(
    "unfollow",
    function(request, response) {
        var currentUserID = request.params.currentuser;

        var followedUserID = new Array(request.params.followeduser);

        var queryRemoveFollower = new Parse.Query("userRelation");
        queryRemoveFollower.containedIn("userObjectId", followedUserID);

        queryRemoveFollower.find({
            success: function(result) {
                for(var i=0; i<result.length; i++) {
                    result[i].remove("followers", currentUserID);
                    result[i].save();
                }

                var stopFollowingQuery = new Parse.Query("userRelation");
                stopFollowingQuery.equalTo("userObjectId", currentUserID);

                stopFollowingQuery.find({
                    success: function(result) {
                        for(var i=0; i<result.length; i++) {
                            result[i].remove("following", followedUserID);
                            result[i].save();
                        }

                        response.success("Unfollow succesful!");
                    },
                    error: function(error) {
                        response.success("Something went wrong. Error code: " + error.code + ", error message: " + error.message);
                    }
                });
            },
            error: function(error) {
                response.success("Something went wrong. Error code: " + error.code + ", error message: " + error.message);
            }
        });
    }
);

I know that the data is being currently sent:

fn_unfollow.parse_data_user_id = ruWNYycty7

fn_unfollow.idOfTheUserToUnfollow = KcCNa39sgk

Thanks in advance for the help!!

1 Answer 1

2

The problem in your code is the line:

var followedUserID = new Array(request.params.followeduser);

JavaScript's Array constructor has two possible constructors:

new Array(element0, element1, ..., elementN)
new Array(arrayLength)

Since request.params.followeduser is an integer, folowedUserID is being initalized as a EMPTY array with length of request.params.followeduser.

The fix is to use either of the following (untested...):

var followedUserID = new Array(1, request.params.followedUser);

or (preferred):

var followedUserId = [request.params.followedUser];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.