Paul Medawar
Posts: 0
Joined: Thu Apr 03, 2014 10:55 am

multiUpdateObject Array from example

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.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

multiUpdateObject Array from example

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?

Paul Medawar
Posts: 0
Joined: Thu Apr 03, 2014 10:55 am

multiUpdateObject Array from example

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.

Paul Medawar
Posts: 0
Joined: Thu Apr 03, 2014 10:55 am

multiUpdateObject Array from example

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.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

multiUpdateObject Array from example

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"

Paul Medawar
Posts: 0
Joined: Thu Apr 03, 2014 10:55 am

multiUpdateObject Array from example

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?

Paul Medawar
Posts: 0
Joined: Thu Apr 03, 2014 10:55 am

multiUpdateObject Array from example

any update for this?

Paul Medawar
Posts: 0
Joined: Thu Apr 03, 2014 10:55 am

multiUpdateObject Array from example

Hi, any update on this?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

multiUpdateObject Array from example

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

Paul Medawar
Posts: 0
Joined: Thu Apr 03, 2014 10:55 am

multiUpdateObject Array from example

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'}

?

Return to “Issues”