I'm trying to add another variable to the user entity. I want the user to be able to click a button and save their current location for later use. However, I can't seem to be able to find a way to edit the user entity. Right now I am using something like this:
var savedLocation = { "latitude": lat, "longitude": lng }; var ql = "username='" + username + "'"; var user = new Apigee.Collection({ 'client':client, 'type':'users', 'qs': { 'ql': ql } }); user.fetch( function(err, data){ if (err){ console.log("read failed"); }else{ while(user.hasNextEntity()){ var currentUser = user.getNextEntity(); currentUser.savedLocation = savedLocation; currentUser.save(); } } } ); user.savedLocation = savedLocation;
Is there a way to do this or am just going to have to create a separate database for user's saved locations?
I believe that should work. Before I dig into this any further, can you tell me if you are getting a permissions error with this or if the save is just not working?
Answer by Michael Malloy
·
Dec 15, 2014 at 09:06 PM
You should be able to add fields to entities of the users collection like any other collection. The only reserved words are username, email and password. Once you find the entity you want to change, set the field name equal to the value you want and save the entity.
Your code looks correct except I don't think user.savedLocation = savedLocation; will work because user is an Apigee collection and not an entity.
How to get Group Users using android sdk. 2 Answers
Bass subscriber internal to external 1 Answer
GET on resource not returning anything but Duplicate error on POST 2 Answers
Sync stage data store with production 3 Answers
where can I find "create" and "run query" buttons in the Baas console? 1 Answer