Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

object not found for update #597

Closed
redblinkdevs opened this issue Feb 23, 2016 · 2 comments
Closed

object not found for update #597

redblinkdevs opened this issue Feb 23, 2016 · 2 comments

Comments

@redblinkdevs
Copy link

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

@gfosco
Copy link
Contributor

gfosco commented Feb 23, 2016

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.

@gfosco gfosco closed this as completed Feb 23, 2016
@redblinkdevs
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants