Upgraded to Mongoose 5.0.13 - getting a 500 in angular-fullstack generated app from a bluebird error: Error: expecting an array, a promise
Upgraded to Mongoose 5.0.13 - getting a 500 in angular-fullstack generated app from a bluebird error: Error: expecting an array, a promise
我有一个应用程序是在 之前使用 angular-fullstack 生成器创建的。一切都很好,直到我们需要升级我们的 mongoose 以获得 bulkwrite。好吧,当我们到达 mongoose 4.11.13(或 4.>8。我不记得具体版本,但它大于 4.8 且 < 5)时,我们的 socket.io 崩溃了。升级到 Mongoose 5.0.13 解决了套接字问题并具有批量写入功能,但是现在大多数更新在保存到 mongo 时会抛出 500 错误:
TypeError: expecting an array, a promise or a thenable
See https://github.com/petkaantonov/bluebird/wiki/Error:-expecting-an->array,-a-promise-or-a-thenable
PUT /api/accounts/57488f5ac260210300c10d80 500 77.719 ms - 2
这是导致错误的方法:
// Updates an existing Account in the DB
export function update(req, res) {
if (req.body._id) {
delete req.body._id;
}
Account.findByIdAsync(req.params.id)
.then(handleEntityNotFound(res))
.then(saveUpdates(req.body))
.then(responseWithResult(res))
.catch(handleError(res));
}
来自样板文件生成器
我通过删除其他内容将其缩小到 saveUpdates(req.body)。对数据库的更新发生并持续存在,但他们发现了一个错误。
这是 saveUpdates 方法 - 再次来自生成器。
function saveUpdates(updates) {
return function(entity) {
var updated = _.merge(entity, updates);
return updated.saveAsync()
.spread(updated => {
return updated;
});
};
}
我想我已经接近找到其他接近的解决方案并且我已经尝试过它们但它无助于解决错误。
有没有人以前遇到过这个问题或者知道如何重构它以便能够使用最新的 mongoose?
@Roamer-1888 我解决了这个问题。从 angular-fullstack-generator 开始,原始样板代码在猫鼬 5 中不起作用。
原始样板 saveUpdates() 是这样的:
function saveUpdates(updates) {
return function(entity) {
var updated = _.merge(entity, updates);
return updated.saveAsync()
.spread(updated => {
return updated;
});
};
}
根据 pm @Roamer-1888 的说明,我做了以下更改,500 错误消失了:
function saveUpdates(updates) {
return function(entity) {
return _.merge(entity, updates).saveAsync()
.then(updated => updated);
};
}
问题解决了!谢谢@Roamer-1888
我有一个应用程序是在 之前使用 angular-fullstack 生成器创建的。一切都很好,直到我们需要升级我们的 mongoose 以获得 bulkwrite。好吧,当我们到达 mongoose 4.11.13(或 4.>8。我不记得具体版本,但它大于 4.8 且 < 5)时,我们的 socket.io 崩溃了。升级到 Mongoose 5.0.13 解决了套接字问题并具有批量写入功能,但是现在大多数更新在保存到 mongo 时会抛出 500 错误:
TypeError: expecting an array, a promise or a thenable
See https://github.com/petkaantonov/bluebird/wiki/Error:-expecting-an->array,-a-promise-or-a-thenable
PUT /api/accounts/57488f5ac260210300c10d80 500 77.719 ms - 2
这是导致错误的方法:
// Updates an existing Account in the DB
export function update(req, res) {
if (req.body._id) {
delete req.body._id;
}
Account.findByIdAsync(req.params.id)
.then(handleEntityNotFound(res))
.then(saveUpdates(req.body))
.then(responseWithResult(res))
.catch(handleError(res));
}
来自样板文件生成器
我通过删除其他内容将其缩小到 saveUpdates(req.body)。对数据库的更新发生并持续存在,但他们发现了一个错误。
这是 saveUpdates 方法 - 再次来自生成器。
function saveUpdates(updates) {
return function(entity) {
var updated = _.merge(entity, updates);
return updated.saveAsync()
.spread(updated => {
return updated;
});
};
}
我想我已经接近找到其他接近的解决方案并且我已经尝试过它们但它无助于解决错误。
有没有人以前遇到过这个问题或者知道如何重构它以便能够使用最新的 mongoose?
@Roamer-1888 我解决了这个问题。从 angular-fullstack-generator 开始,原始样板代码在猫鼬 5 中不起作用。
原始样板 saveUpdates() 是这样的:
function saveUpdates(updates) {
return function(entity) {
var updated = _.merge(entity, updates);
return updated.saveAsync()
.spread(updated => {
return updated;
});
};
}
根据 pm @Roamer-1888 的说明,我做了以下更改,500 错误消失了:
function saveUpdates(updates) {
return function(entity) {
return _.merge(entity, updates).saveAsync()
.then(updated => updated);
};
}
问题解决了!谢谢@Roamer-1888