我正在运行Parse-Server v2.2.22我的解析DB。看来我的服务器无法接受所有保存请求。我在消息中遇到了一个code 100
错误:XMLHttpRequest failed: "Unable to connect to the Parse API"
大约60%的保存请求。
我的代码看起来像这样:
makeHttpRequest('GET', endpoint).then( (httpResponse) => {
const dataArray = httpResponse.body.array;
const Class = Parse.Object.extend('className');
const savePromises = _.map(dataArray, (jsonObject) => {
const object = new Class();
object.set(IdKey, "" + jsonObject.id);
object.set(nameKey, jsonObject.name);
return object.save(null, {useMasterKey: true});
});
return Parse.Promise.when(savePromises);
});
我尝试将数组分为三分之二(〜4.5k记录)并使用promise.then
依次执行每组保存,但我仍然得到:
{
"code": 100,
"message": "XMLHttpRequest failed: "Unable to connect to the Parse API""
}
update :将此作业迁移到启用了HTTPS的生产服务器后,我收到了稍有不同的错误消息,并且保存了更多。由于我们的生产服务器的额外能力,我怀疑更多的保存。新错误看起来像:
{
"code": 100,
"message": "XMLHttpRequest failed: {"UNSENT":0,"OPENED":1,"HEADERS_RECEIVED":2,"LOADING":3,"DONE":4,"readyState":4,"responseText":"","responseXML":"","status":504,"statusText":null,"withCredentials":false}"
}
i通过使用Parse.Object.saveAll(objects)
解决了这一点。现在,我没有任何问题将所有13K记录保存在一口气中。代码看起来像这样:
makeHttpRequest('GET', endpoint).then( (httpResponse) => {
const dataArray = httpResponse.body.array;
const Class = Parse.Object.extend('className');
const allObjects = _.map(dataArray, (jsonObject) => {
const object = new Class();
object.set(IdKey, "" + jsonObject.id);
object.set(nameKey, jsonObject.name);
return object;
});
return Parse.Object.saveAll(allObjects, {useMasterKey: true});
});
现在一切似乎都很好。