Page 1 of 2

multiUpdateObject Array from example

Posted: Fri Jul 21, 2017 10:07 am
by Paul Medawar

I'm trying to use this example from your multiUpdateObject reference

var dbApiKey = "57928860e4b00ef864f3dc24"
var result = Collection.multiUpdateObject(dbApiKey, "Student", '{isTransferStudent: true}', {"major": {'name':'undecided'}
});

I have two columns in a collection caller EntriesArray

User - String
Selection - Array

in two rows I have the following data

User - Fred
Selection - [{"Player":"WATSON","Points":"2"},{"Player":"JOHNSON","Points":"6"}]

User - Frank
Selection - [{"Player":"GEOFF","Points":"5"},{"Player":"JOHNSON","Points":"6"}]

Following your example I am trying variations of this server code with no joy

var dbApiKey = "*********************"
var result = Collection.multiUpdateObject(dbApiKey, "EntriesArray", '{Selection: {Player:"JOHNSON"}', {"Selection": {'Points':'8'}
});

in which I am trying to change the "Points" value of every "Player" called JOHNSON to 8.

I have also tried using your code exactly as specified targeting all Points, with no joy.

Am I missing something?

No error message is appearing, and no updates are occurring.


multiUpdateObject Array from example

Posted: Sat Jul 22, 2017 7:25 am
by Serhii Kulibaba

Hello Paul,

1) According to our documentation, you have to use a "$set" parameter there:
pre Collection.multiUpdateObject(dbApiKey, "Student", '{isTransferStudent: true}', null, {
"$set": {"isTransferStudent":false}
});/pre
2) Do you want to update values, which are located in the pointers to another collection there?


multiUpdateObject Array from example

Posted: Sat Jul 22, 2017 7:44 am
by Paul Medawar

Hi Serhii,

1 I'm trying the following

------------

var dbApiKey = "**********************";
var result = Collection.multiUpdateObject(dbApiKey, "EntriesArray", '{User: "Frank"}', null, {
"$set": {"Selection.Points":"11"}
});

------------

and getting this error message

"code": "DBSM605",
"message": "Field 'Selection.Points' absent in collection structure"

2 I was just trying to manually input the values straight in to server code for now. But if you have a tutorial or example of updating values which are located in the pointers to another collection, that would also be great.


multiUpdateObject Array from example

Posted: Sat Jul 22, 2017 8:46 am
by Paul Medawar

I've also tried

var dbApiKey = "********************";
var result = Collection.multiUpdateObject(dbApiKey, "EntriesArray", '{Selection:{Player:"JOHNSON"}', null, {
"$set": {"Selection" :{"Points":"11"}}
});

with the following error message

"code": "DBSM602",
"message": "Native operation works on fields with following types: number, string, boolean, date"

This is actually explained in your documentation and the reason i used the other example in your documentation which is this structure

https://docs.appery.io/reference#serv...

var dbApiKey = "57928860e4b00ef864f3dc24"
var result = Collection.multiUpdateObject(dbApiKey, "Student", '{isTransferStudent: true}', {"major": {'name':'undecided'}
});

as shown in my initial question.


multiUpdateObject Array from example

Posted: Sun Jul 23, 2017 8:24 am
by Serhii Kulibaba

It is impossible to use multiUpdateObject method for pointers. The native operation works on fields with following types: number, string, boolean, date. So if you need to update pointer values, you have to run update service for all these rows or use the method "multiUpdateObject" for the collection "Selection" directly, instead of "EntriesArray"


multiUpdateObject Array from example

Posted: Sun Jul 23, 2017 8:57 am
by Paul Medawar

Hi Serhii,

The database column is not a pointer, it's an array.

Your documentation

https://docs.appery.io/reference#serv...

has the following example

---------------------------

The following examples finds all students who are transfer students and the update sets their major to undecided. This examples uses updateJSON parameter.

var dbApiKey = "57928860e4b00ef864f3dc24"
var result = Collection.multiUpdateObject(dbApiKey, "Student", '{isTransferStudent: true}', {"major": {'name':'undecided'}
});

---------------------------

I'm presuming that in this example

  • "Student" - is the collection

  • '{isTransferStudent: true}' - is the query relating to column "isTransferStudent"

  • {"major": {'name':'undecided'} - "major" is the column, and "name" is a value in the array in that column to be updated to "undecided"

    and therefore multiUpdateObject can be used to update arrays?


multiUpdateObject Array from example

Posted: Mon Jul 24, 2017 4:59 pm
by Paul Medawar

any update for this?


multiUpdateObject Array from example

Posted: Wed Jul 26, 2017 5:57 am
by Paul Medawar

Hi, any update on this?


multiUpdateObject Array from example

Posted: Wed Jul 26, 2017 8:12 am
by Serhii Kulibaba

Please see my answer above:

The native operation works on fields with following types: number, string, boolean, date

Unfortunately, they don't work with pointers, objects and arrays


multiUpdateObject Array from example

Posted: Wed Jul 26, 2017 11:15 am
by Paul Medawar

Hi Serhii,

ok can you help me with the database structure for the example you give in your documentation, so I can understand

https://docs.appery.io/reference#serv...

---------------------------

The following examples finds all students who are transfer students and the update sets their major to undecided. This examples uses updateJSON parameter.

var dbApiKey = "57928860e4b00ef864f3dc24"
var result = Collection.multiUpdateObject(dbApiKey, "Student", '{isTransferStudent: true}', {"major": {'name':'undecided'}
});

---------------------------

I want to recreate from this example. So I'm presuming

"Student" is the collection
"isTransferStudent" is a Column of type boolean

what is the database structure for the

{"major": {'name':'undecided'}

?