If you are using Parse backend in one of your application/game like me, you already sadly know that Parse’s backend services will be fully retired on January 28, 2017 and you probably started to migrate your data and cloud code to an alternative db and backend service.
I have already started to migration process and decided to try MongoLab and AWS. Before to deploy our cloud code to AWS, I set up parse server environment on my local computer and running parse service succesfully. Problem is that when I call Parse.Promise.when() with multiple commands like that :
return Parse.Promise.when([query1, query2]).then(function () {
console.log("arguments : " + JSON.stringify(arguments));
...
...
);
it returns different result than I am getting from parse servers. Difference is that returning json object on my local computer has only one key as “0” and an object array as value.
{
"0":[
{QuestionObject},
{QuestionObject},
....
{QuestionObject}
]
}
On the parse server instance, the same query gives the following result :
{
"0":{QuestionObject},
"1":{QuestionObject},
...
"16":{QuestionObject}
}
I firstly suspect that MongoDB configurations are different and that’s why the data has been retrieved in different format and saw this doesn’t make sense after 30 minutes of investigation.
Finally we found that the root cause of this issue is a commit made on Parse Javascript SDK. Brief of this commit is seen as below:
var arrayArgument = Array.isArray(promises);
var returnValue = arrayArgument ? [results] : results;
Here, “promises” is input queriy you pass into Parse.Promise.when() and you can see that if your input is an array, so consist of multiple queries, then square brackets are applied to returning object. This code change is commited on December 10, 2015 and reverted on January 09, 2016 with this revert commit.
For resolving this issue, I have downloaded the latest Parse JS SDK and replaced ParsePromise.js with up to date version.