parse-server: Parse relation schema mismatch when passing in array of objects

Environment Setup

  • Parse Server 2.1.5
  • Localhost
  • Node 5.5
  • Mongo 3.1.9

Steps to reproduce

It seems like the below code in my User’s afterSave is causing a problem

feed.relation('forUsers').add(otherUsersInFamily);

otherUsersInFamily is just an array of Parse.User returned by a Parse.Query. When I tried a basic setup creating a Feed and adding forUsers (from a Parse.Query) it works. Its a wierd situation if you need more information please let me know

This particular line is causing an error

schema mismatch for Feed.forUsers; expected relation<_User> but got object

More code

userAfterSave: function(req) {
        var Feed = Parse.Object.extend('Feed');

        var user = req.object;
        var otherUsersInFamily = [];

        if (!user.get('family'))
            return console.log('user not in family', user.id);

        var query = new Parse.Query(Parse.User);
        query.equalTo('family', user.get('family'));
        query.notEqualTo('objectId', user.id);
        query.find()
            .then(function(users) {
                otherUsersInFamily = users;

                if (user.get('joinedFamily') !== true)
                    return;

                var promises = [];

                // add feed
                var feed = new Feed({
                    actor: user.toPointer(),
                    action: 'joined family',
                    title: user.get('family'),
                    subjectType: 'FamilyEvent',
                    subjectAction: 'joined'
                });
                console.log('user id', user.id, otherUsersInFamily)
                feed.relation('forUsers').add(otherUsersInFamily);     // <<< --- When this is commented things no error occur

                return feed.save();
            })
            .fail(function(err) {
                console.error(`User.afterSave Failed: ${user.id}, ${err.message}`);
                return Parse.Promise.error(err.message);
            });
}

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

I also ran into this error but the reason is because I had created Collections in the db and, some time later, I changed the data structure of the Documents I was saving in that same Collection.

Have you changed the structure of any of the Documents since you began writing them to the db?

In my case, I had been using myParseObject.add() to add key/values, which actually performs operations on arrays. I realized later that I needed to use myParseObject.put() in order to simply have a key/value pair rather than an array. And that’s when I started getting the error because I was saving to an existing Collection but with a different data structure than what is already saved in the db.

Here’s the error I got:

com.parse.ParseRequest$ParseRequestException: schema mismatch for Profile.address; expected [object Object] but got String

To fix the problem:

I’m using a MongoDB and I deleted all Documents in the Collection named Profile. But that wasn’t enough. I needed also to go into the _Schema Collection and delete any old definition of the Profile Collection there as well. Once I did that everything began working again.

To troubleshoot you should try changing the Class name of your ParseObject and see if it saves without error.

For example if you have: ParseObject object = new ParseObject(“MyProfile”) then try changing it to: ParseObject object = new ParseObject(“TestProfile”)

If using a new class name for the ParseObject saves without error then you may have old Collections by the original name hanging around the db or in the _Schema. Clean them up and try again.