Parse-server: changing a field value in Users, not saving

Created on 23 Jun 2016  路  5Comments  路  Source: parse-community/parse-server

I am trying to change a field called "name" for an already existing user.
however, i cannot seem to get any response from saving the change as seen below.

Steps to reproduce

var query = new Parse.Query(Parse.User);
query.equalTo("username", "someUserName");

      query.find({
          success: function(users){
              console.log("user found", users);
               users.set("name", "new name");
               users.save(null,{
                success: function(updated){

              },
              error: function(error, updated){

               }
             });

   },
  error: function(error, users){
        console.error("error at querying: ", error);
   }

});

Expected Results

did not work, so i looked it up an it appears i need to use the master key. i have tried to as in the mini snippet below

users.save(null,{useMasterKey:true}{
success: function(updated){
//updated
}

However that did not work out as well. Im fairly new to parse server, and i would appreciate any idea where i might have gone wrong

Environment Setup

  • Server

    • parse-server version: 2.2.2

Most helpful comment

A query returns an array of objects, but your code assumes "users" is a Parse object. Fixing that should take care of your issue.

Closing this at it seems to be a general code-level question about using the Parse SDK.

For code-level and/or implementation-related questions or technical support, please refer to Stack Overflow.

All 5 comments

One recommendation for starters would be to update to the latest version of parse-server. That way you rule out any old bugs or issues. You are running an old version. Current is v2.2.13

i shall try that

I tested this on my local parse-server (2.2.13) and could not get it to work either.

However, I do believe your save code should look like this.

  users.save(null, {
    useMasterKey: true,
    success: function(updated){
      //updated
    }
  });

useMasterKey is part of the options parameter object along with success and error according to the docs:
https://parse.com/docs/js/api/classes/Parse.Object.html#methods_save

None of this will work for me either so maybe someone else will chime in...

It's possible you might need the users token in order to make this save. Just another thought.

This is the example used here: https://github.com/ParsePlatform/Parse-Server/wiki/Compatibility-with-Hosted-Parse#Cloud-Code

// Parse Server Cloud Code
Parse.Cloud.define('getMessagesForUser', function(request, response) {
  var user = request.user; // request.user replaces Parse.User.current()
  var token = user.getSessionToken(); // get session token from request.user

  var query = new Parse.Query('Messages');
  query.equalTo('recipient', user);
  query.find({ sessionToken: token }) // pass the session token to find()
    .then(function(messages) {
      response.success(messages);
    });
});

I have tried using the sessionToken within

query.find({
sessionToken: "sessionToken",
success: function(users){...

but that isn't working as well.

A query returns an array of objects, but your code assumes "users" is a Parse object. Fixing that should take care of your issue.

Closing this at it seems to be a general code-level question about using the Parse SDK.

For code-level and/or implementation-related questions or technical support, please refer to Stack Overflow.

Was this page helpful?
0 / 5 - 0 ratings