Eduardo Orozco Sanchez
Posts: 0
Joined: Tue Jun 24, 2014 5:03 pm

How can I modify the value of a field in all the rows of a DB Collection?

Hi.
I am trying to create a server script that increases the value within a field of a collection of the database for all of its rows when it is executed.
Eachvalue is an integer and I want the script to add a the same integer to each value.

For example,
Collection: Values:
Row: 1 Value: 100
Row: 2 Value: 200
Row: 3 Value: 50
Row 4 Value: 125

How can I add 125 to the value in each row and update de Collection?
I would like to update it to:
Row: 1 Value: 225
Row: 2 Value: 325
Row: 3 Value: 175
Row 4 Value: 250

So far I've used the Collection.updateObject command but it only allows me to update 1 row since it requires the row's id, how I can do this for all items in a database?

Thanks!

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

How can I modify the value of a field in all the rows of a DB Collection?

Hello Eduardo,

You can't do this per one request. You can get all the records. You may come on them in the loop and update the value for each entry.

Eduardo Orozco Sanchez
Posts: 0
Joined: Tue Jun 24, 2014 5:03 pm

How can I modify the value of a field in all the rows of a DB Collection?

Thanks Evgene
Can you point me to a resource on how to create a loop in Appery?
I am getting started on this.
Thank you!

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

How can I modify the value of a field in all the rows of a DB Collection?

Eduardo,

You can do this be using JS. Please look for info here: https://developer.mozilla.org/en-US/d...

Return to “Issues”