Skip to content

object not found for update #597

Closed
Closed

Description

@redblinkdevs

Hi ,
i am using parse server and mongo db on ubuntu 14.04 LTS
I have written some cloud script in which
i am getting user object from request and console.log(request.user) print below object
ParseUser { _objCount: 0, className: '_User', id: 'YK8c12J1xb' }

and in mango following row exists.

{ "_id" : "YK8c12J1xb", "address" : "chd", "name" : "Parm", "email" : "parm@gmail.com", "username" : "parm", "_updated_at" : ISODate("2016-02-12T10:49:49.178Z"), "_created_at" : ISODate("2016-02-12T10:49:49.178Z"), "_hashed_password" : "$2a$10$hOMj/0s0AUf6Je/YIuCqU.FAkEoVu3j4IknKsMaYRcLG2LSGcoQV6", "emailVerified" : true }

then i have increment the count by 1 and save that but in error handler "object not found for update " was printing and user not updating .
like below
request.user.increment("publicTitleCount", 1);

request.user.save( {success: function(users) {
},error: function(user, err) {
console.error(err.message);
}});

similarly i have pass user object id to one function

userQuery = new Parse.Query("_User");
console.log(request.params.userObjectId);
userQuery.get(request.params.userObjectId, {

but in this case i am getting "Object not found"

This code is working fine on parse site and its live there.But giving problem on parse server.

Thanks ,
Parminder Ghuman

Activity

  1. gfosco commented on Feb 23, 2016

    @gfosco
    Contributor

    Add the useMasterKey:true option to your save call to affect a user from cloud code:

    user.save(null, { useMasterKey: true }).then((userAgain) => {
     // success
    }, (error) => {
     console.log(error);
    });

    Same with the find:

    userQuery.get(request.params.userObjectId, { useMasterKey: true }).then((user) => {
    
    }, (error) => {
    
    });

    This should solve your issue... let me know if not. Thanks.

  2. redblinkdevs commented on Feb 23, 2016

    @redblinkdevs
    Author

    Hi ,
    I had user this

    var user= request.user;
    if (request.object.get("isPrivate")) {
    user.increment("privateTitleCount", 1);
    } else {
    user.increment("publicTitleCount", 1);
    }
    request.object.increment("subsciptions",1);
    user.set("publicTitleCount", 1);
    console.log(user+" jj");
    user.save(null,{ useMasterKey: true }).then((user) => {
    console.log(user+" saved");
    }, (error) => {
    console.log(error.message+" got error");
    });

    it still print "object not found for update"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions