Search code examples
javascriptnode.jsgoogle-cloud-functionsparse-server

Parse: ParseError { code: 101, message: 'Object not found.' }


I have a cloud function running some code like this and I am able to get a response for my query which is a valid class instance, but when I try to update the instance with the set method, I get the error you see in the title.

async function addToDB(apiKey) {
    const query = new Parse.Query(MyClass);
    query.equalTo('apiKey', apiKey);
    const response = await query.find({ useMasterKey: true });
    const myInstance = response[0];
    myInstance.set('total', 100);
    try {
        await myInstance.save({ useMasterKey: true });
    } catch (e) {
        console.log('E', e);
    }
}

Solution

  • the options parameter ( { useMasterKey : true}) should be the second parameter passed to save

    the first parameter to a save should be a null, i.e. :

    myInstance.save(null, { useMasterKey: true })

    in essence, you are not passing the masterkey option in to the save call - which is why you are getting the 101 error (in my experience, a 101 is almost always related to permissions issues!)

    see more here http://parseplatform.org/Parse-SDK-JS/api/v1.11.1/Parse.Object.html#save