Page 1 of 4

cycle through all users in database

Posted: Thu Jul 09, 2015 2:00 pm
by Terry Gilliver

I have a flag in the _user collection. I want to be able to set this flag in all records of the _user collection. How can I update the entire collection?


cycle through all users in database

Posted: Fri Jul 10, 2015 10:07 am
by Terry Gilliver

I have created a service to list all users and the output is save into an array of users.

I have a 'users' variable saved in session storage, a 'User' Model, which contains all the fields of the _user collection. I have a 'Users' model which is an array of the User Model. The service works correctly and the user variable is loaded. A sample users session variable is as follows:

[{"userId":"55758504e4b0b40eb7813c50","username":"terry","email":"a href="mailto:terry@mrtaxsoftware.com" rel="nofollow"terry@mrtaxsoftware.com/a","firstName":"Terry","lastName":"Gilliver","address":"56 Stowe Close","county":"Leicestershire","town":"Ashby-de-la-Zouch","postcode":"LE65 2NY","telephone":"07925273831","newsAvailable":false,"eventsAvailable":false},{"userId":"5579d8fde4b0b40eb781f335","username":"admin","email":"a href="mailto:terry@mrtaxsoftware.com" rel="nofollow"terry@mrtaxsoftware.com/a","firstName":"Terry","lastName":"Gilliver","address":"56 Stowe Close","county":"Leicestershire","town":"Ashby","postcode":"LE65 2NY","telephone":"07925273831","newsAvailable":false,"eventsAvailable":false}]

I I need to loop through each userId in this array to execute an update service. I am unsure how to get the userId from each array element.

Can you suggest how to do this?


cycle through all users in database

Posted: Fri Jul 10, 2015 11:10 am
by Terry Gilliver

Ok, I figured it out:

code
/* loop through users */
var users = Apperyio.storage.users.get();
var arrayLength = users.length
for (i = 0; i < arrayLength; i++) {
console&#46;log(users&#46;userId);
}/code


cycle through all users in database

Posted: Fri Jul 10, 2015 12:52 pm
by Terry Gilliver

Proceeding a bit further now, I want to run the update service for the users collection.

My code now reads:

code/* loop through users */
var users = Apperyio&#46;storage&#46;users&#46;get();
var arrayLength = users&#46;length;
for (i = 0; i < arrayLength; i++) {
console&#46;log(users&#46;userId);
updateUsers&#46;execute({body : {where : {user_id : users&#46;userId}, operations : {$set : {events_available : true} } } });
}/code

The update fails and the console log entry is:

PUT https://api.appery.io/rest/1/db/users/ 405 (Method Not Allowed)

My update service works if you map the data via the graphical interface, so it must be a syntactical error in my call to the service.

The service is defined as :

Image

Image

Image

Image

Can you advise where my error is?


cycle through all users in database

Posted: Fri Jul 10, 2015 2:42 pm
by Terry Gilliver

Is there any documentation which fully describes the javascript syntax of a service.execute({}) statement? It seems to be a bit sparse.


cycle through all users in database

Posted: Fri Jul 10, 2015 3:44 pm
by Illya Stepanov

Hi Terry -

Let's start from the error that you are getting, could you please check the network tab in the browser console -- what are you getting there as a response from your service call?


cycle through all users in database

Posted: Fri Jul 10, 2015 5:00 pm
by Terry Gilliver

{"code":"DBUQ002","description":"database id not specified"}

However, I don't understand this as here is the mapping

Image


cycle through all users in database

Posted: Fri Jul 10, 2015 8:24 pm
by Illya Stepanov

Try to pass headers parameters within execution of your service this way: https://devcenter.appery.io/documenta...

And in network tab you should be able to see what parameters you are sending with your service invocation.


cycle through all users in database

Posted: Tue Jul 28, 2015 10:09 pm
by Jack Bua

I too am getting this error when trying to build a service on the users collection:

{
"status":400,
"uri":"https://api.appery.io/rest/1/db/users/",
"response":{
"code":"DBUQ002",
"description":"database id not specified"
}
}

I am using a REST Service, and in the Header request parameter I have
X-Appery-Database-Id. I have tried using {database_id} and the actual ID, no luck. I cannot get this to work in test.

I followed instructions from Yurii:
https://getsatisfaction.com/apperyio/...

DB is shared with support already.


cycle through all users in database

Posted: Sat Aug 01, 2015 4:46 am
by Evgene Karachevtsev

Jack,

Could you please specify the name of this db?