mongodb - 当我想使用 mongoose session transaction 使用 mongoose 的 updateMany() 函数时出现此错误
问题描述
错误 [ERR_UNHANDLED_ERROR]:未处理的错误。(null) 我该如何解决这个问题?在 node.js 中使用事务进行复制后,我在 E:\dev\node js\chat project\node_modules\mongoose\lib\model.js:5067 的 Function.emit (events.js:304:17) 收到此错误: 15 在 processTicksAndRejections (internal/process/task_queues.js:75:11) { 代码:'ERR_UNHANDLED_ERROR',上下文:空
try {
if (deleteOnBothSides) {
await PvMessageModel.updateMany(
{_id: {$in: messageIds}, from: actorId},
{$set: {is_deleted_from: true, is_deleted_to: true}},
(e, messages) => {
throw e
}).session(session)
await PvMessageModel.updateMany(
{_id: {$in: messageIds}, to: actorId},
{$set: {is_deleted_to: true}},
(e, messages) => {
throw e
}).session(session)
} else {
await PvMessageModel.updateMany(
{_id: {$in: messageIds}, from: actorId},
{$set: {is_deleted_from: true}},
(e, messages) => {
throw e
}).session(session)
await PvMessageModel.updateMany(
{_id: {$in: messageIds}, to: actorId},
{$set: {is_deleted_to: true}},
(e, messages) => {
throw e
}).session(session)
}
await session.commitTransaction();
socket.emit('privateChatDeleteMessageResponse', {
actor_id: actorId,
message_ids: messageIds,
})
if (deleteOnBothSides)
client.get(otherSideId, (e, reply) => {
if (e) {
ErrorHandler.saveError(e, 'Node.js', currentFileName, 'socket.on("privateChatDeleteMessageResponse")', 6);
throw e;
}
if (reply != null)
// emmit to another side of chat if message deleter equals to message sender and delete on both sides is true
io.to(reply).emit('privateChatDeleteMessageResponse', {
actor_id: actorId,
message_ids: messageIds,
})
})
} catch (e) {
ErrorHandler.saveError(e, 'Node.js', currentFileName, 'socket.on("privateChatDeleteMessage")', 7);
} finally {
session.endSession();
}
解决方案
推荐阅读
- reactjs - ID 不能表示非字符串和非整数值
- python - 我应该如何让我的不和谐机器人欢迎某人?
- python - let e1 in e2 的明确语法
- node.js - 无法在 Nodejs 中利用 Json 发布数据的对象字段
- python - 按每个数组比较两个 numpy 数组的张量 - tensorflow
- google-bigquery - 您可以使用 Tableau 在 BigQuery 中创建预聚合维度/度量(如 OLAP)吗?
- c# - Clickonce 离线安装管理
- python - 连接客户端套接字和服务器套接字的问题
- http - 带有查询参数的请求失败
- python - 我试图在我的 python 应用程序上统一单词