GregMc
Posts: 0
Joined: Wed Dec 03, 2014 12:46 am

problem with Collection.multiUpdateObject

Hi , I am writing a server script in which I need to use Collection.multiUpdateObject. I have been unable to get it to work successfully, I keep running in to the following error:

Script scoring_script: Error: argument type mismatch ( @ 37 : 18 ) - throw e;

The call I am using is below:

result.answersquery = Collection.multiUpdateObject(db_id, "answers", ms_answer_params, {$mul:{score: 2.5}});

I have used a Collection.query statement successfully as below:
result.answersquery = Collection.query(db_id, "answers", ms_answer_params);

since the db_id, "answers", and ms_answer_params are common between the 2 statements and the query statement works while the multiUpdateObject does not I am left to assume the problem is with the JSON operation parameter of "{$mul:{score: 2.5}}"

I have fully read the doc at http://devcenter.appery.io/documentat... and the mongoDB doc for the multiply operation at: http://docs.mongodb.org/manual/refere...

As far as I can tell I am using a valid JSON operation parameter. What am I doing wrong?

GregMc
Posts: 0
Joined: Wed Dec 03, 2014 12:46 am

problem with Collection.multiUpdateObject

I am continuing to try and get this working but no success. I have read through the documentation again for multiUpdateObject again and am very confused by the last 2 parameters:

updateJSON – JSON object with fields of object that should be updated.

operationsJSON – is JSON update object with native mongo operations and fields of object that should be updated. Object was built in accordance with the documentation of mongo set operations. If object specified than update param fully ignored. Their functionality can not be used simultaneously.

The doc says that these 2 parameters cannot be used simultaneously but in the method definition they are both shown in bold meaning they are both required. I just find the doc very unclear on how to specify these 2 parameters. There is no example in the doc for this method so I have resorted to trial and error. I have most recently tried this call but I get an unexpected token error:

result.answersquery = Collection.multiUpdateObject(db_id, "answers", ms_answer_params, {"score"}, {$mul:{score: 2.5}});

I basically have a column in the "answers" collection named score and for all rows that match the query criteria I want to multiply the existing value in score column by 2.5. Can someone please help with this?

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

problem with Collection.multiUpdateObject

Hi GregMC,

Here is worked code that you can use as worked example:

precode

var responseBody = {},
requestParams = {},
paramKeys = request.keys();

for (var key = 0; key < paramKeys&#46;length; key++) {
requestParams[paramKeys[key]] = request&#46;get(paramKeys[key]);
}

&#47;&#47;Settings:
var dbId = "52fd3d06e4b0a25c11c89917&quot
var collectionName = "dogs&quot
var itemId = "53ba2599e4b09f5c7d50390f&quot

var queryString = '{name: "query"}';
var updateJSON = {number: 1};
var operationsJSON = {$set: {number: 3}};
var token;

Collection&#46;multiUpdateObject(dbId, collectionName, queryString, updateJSON, operationsJSON)

responseBody&#46;requestBody = request&#46;body();
responseBody&#46;requestParams = requestParams;
console&#46;log(responseBody);
response&#46;success(responseBody, "application/json");

/code/pre

Regards.

GregMc
Posts: 0
Joined: Wed Dec 03, 2014 12:46 am

problem with Collection.multiUpdateObject

Thanks Yuri but I am still not clear on how the updateJSON and operationsJSON relate to eachother. So for your example does the updateJSON set the value of the "number"column to 1 and then the operationsJSON sets the value of the "number" column to 3?

If so I still don't understand how to implement this in my case. I have a column named "score", there is already a value in the score column so I do not want to set the existing value to anything new, I just want to multiply the existing value in the "score" column by 2.5.

So could you provide the updateJSON and operationsJSON parameter I should use if I have a column named "score" and I only want to multiply the existing value in score by 2.5?

Thanks.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

problem with Collection.multiUpdateObject

Greg,

  1. You can comment following line of code:

    pre

    &#47;&#47;var updateJSON = {number: 1};

    /pre

  2. You can not update with value which is where in this field before. You should have certain value to update. So you can get this value before and then you can compute it and pass to the "set" parameter.

    Regards.

GregMc
Posts: 0
Joined: Wed Dec 03, 2014 12:46 am

problem with Collection.multiUpdateObject

Hi Yurri,

But if I comment this declaration out then I get an error that the variable is undefined in the method call. Should I also remove the updateJSON parameter from the method call?

I have tried to get this to work again based on what you said in #2 above but I still am getting and argument type mismatch error.

I have been stuck on this single method call for more than 2 days so can I request that you please look in to my app? I have shared the server side script and library as well as my database with appery support.

The script to run is called score_challenge_script, this script calls a function in a library, the function is called score_challenge_answers and in this function the multiUpdateObject call is on line 55.

I feel like I must be doing something basic wrong that I am missing, can you please take a look?

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

problem with Collection.multiUpdateObject

Hi GregMC,

Unfortunatly i can not see your script shared with us.

But here is worked script with commented line:

pre

var responseBody = {},
requestParams = {},
paramKeys = request&#46;keys();
for (var key = 0; key < paramKeys&#46;length; key++) {
requestParams[paramKeys[key]] = request&#46;get(paramKeys[key]);
}
&#47;&#47;Settings:
var dbId = "52fd3d06e4b0a25c11c89917";
var collectionName = "dogs";
var itemId = "53ba2599e4b09f5c7d50390f";
var queryString = '{name: "query"}';
var updateJSON = {
&#47;&#47;number: 1
};
var operationsJSON = {$set: {number: 3}};
var token;
Collection&#46;multiUpdateObject(dbId, collectionName, queryString, updateJSON, operationsJSON)
responseBody&#46;requestBody = request&#46;body();
responseBody&#46;requestParams = requestParams;
console&#46;log(responseBody);
response&#46;success(responseBody, "application/json");

/pre

Regards

Return to “Issues”