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

Unable to update Parse User field #3522

Closed
Treverr opened this issue Feb 17, 2017 · 1 comment
Closed

Unable to update Parse User field #3522

Treverr opened this issue Feb 17, 2017 · 1 comment

Comments

@Treverr
Copy link

Treverr commented Feb 17, 2017

We use GitHub Issues for bugs.

If you have a non-bug question, ask on Stack Overflow or Server Fault:

You may also search through existing issues before opening a new one: https://github.com/ParsePlatform/Parse-Server/issues?utf8=%E2%9C%93&q=is%3Aissue

--- Please use this template. If you don't use this template, your issue may be closed without comment. ---

Issue Description

When attempting to retrieve a user to update, I cannot update my admin field. My javascript code stops after calling the user but it will not allow me to update fields. I have attempted using the master key and I am still unable to actually load the user.

Steps to reproduce

`Parse.Cloud.define("modifyAdminStatus", function(request, response) {

var userQuery = new Parse.Query(Parse.User);
var isAdmin = request.params.adminStatus
userQuery.equalTo("username", request.params.username);
userQuery.find({ useMasterKey: true,
	success: function(user) {
		console.log(user.length);
		console.log("Got User")
		console.log(user);
		user.set("isAdmin", isAdmin);
		console.log("Set Status");
		user.save(null, {useMasterKey: true,
			success: function(user) {
				response.success();
			},
			error: function(error) {
				response.error(error.message);
			}
		});
	},
	error: function(error) {
		response.error(error.message);
	}
});

});`

The output I get in console is:

1 Got User [ ParseUser { _objCount: 46, className: '_User', id: '2vigcitsl6' } ]

Expected Results

Update and save the user

Actual Outcome

Code is stopped and does not update the user

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : 2.3.3
    • Operating System: Linux 16.1
    • Hardware: Intel NUC Celeron 4GB Ram 500GB 7200rpm
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): Local server
  • Database

    • MongoDB version: 2.6.11
    • Storage engine:
    • Hardware: Same as above
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): Local

Logs/Trace

Include all relevant logs. You can turn on additional logging by configuring VERBOSE=1 in your environment.

@natanrolnik
Copy link
Contributor

@Treverr the query's find() method returns an array of objects - in this case, users... you even log to the console how many objects are in that array (1), and you can see that it logs with [] indicating it's an array and not a single object.

You have two options:
1 - declare users or results as the object returned by the query, and access the first result as:
var user = results[0];
2 - simply use the query's first() method, that already gives you a single object.

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