Jon Haider
Posts: 0
Joined: Thu Oct 16, 2014 2:53 pm

How to update device info in DB from server code script using Collection.updateObject()?

I would like to upload information about my logged-in user to the devices collection in the DB. Currently, I am using a devicesRESTservice call (to this URL: https://api.appery.io/rest/push/reg) from the device and it works perfectly. The good thing about this approach is that I can add the info to the correct row in the DB using the pushNotificationDeviceID: Image

From the server code, I have only been able to get this to work by first running a query of all devices with the correct deviceID (this should return 1 entry) and then I have to run a second DB call to update it:
pre
//updateDevices:
queryParams.criteria = {"deviceID" : deviceID};
//Call 3: Find Device in DB
var devicesQuery = Collection.query(DB_id, "_devices", queryParams, masterKey);

if (devicesQuery.length == 1){
//Device was correctly registered in the DB
var devices_id = devicesQuery[0].id;
//update it with user info
updateParams = {
"usernameB" : username,
"sessionStatus" : userData.userType,
"location" : [myLat, myLng],
"owner" : {"collName": "users", "id": myID}
}
//Call 4: Update Device Info in DB
Collection.updateObject(DB_id, "_devices", _devices_id, updateParams, masterKey);
/pre

Is there any way to achieve this in 1 call from the server code since it can be done in one call from the devicesRESTservice?

Return to “Issues”