Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

cycle through all users in database

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?

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

cycle through all users in database

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?

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

cycle through all users in database

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

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

cycle through all users in database

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?

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

cycle through all users in database

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

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

cycle through all users in database

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?

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

cycle through all users in database

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

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

Image

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

cycle through all users in database

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.

Jack Bua
Posts: 0
Joined: Sun Jun 28, 2015 10:16 pm

cycle through all users in database

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.

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

cycle through all users in database

Jack,

Could you please specify the name of this db?

Return to “Issues”