我正在使用 Feathers 4.5.0 和 Mongo 5.0.2 。我想对集合执行 Mongo DB 事务。我将feather-mongoose文档中的示例复制到我的服务挂钩中。
const TransactionManager = require('feathers-mongoose').TransactionManager;
const isTransactionEnable = process.env.TRANSACTION_ENABLE || false;
const skipPath = ['login'];
let moduleExports = {
before: {
all: [],
find: [],
get: [],
create: [
when(isTransactionEnable, async hook =>
TransactionManager.beginTransaction(hook, skipPath)
)
],
update: [
when(isTransactionEnable, async hook =>
TransactionManager.beginTransaction(hook, skipPath)
)
],
patch: [],
remove: []
},
after: {
all: [],
find: [],
get: [],
create: [when(isTransactionEnable, TransactionManager.commitTransaction)],
update: [when(isTransactionEnable, TransactionManager.commitTransaction)],
patch: [],
remove: []
},
error: {
all: [],
find: [],
get: [],
create: [when(isTransactionEnable, TransactionManager.rollbackTransaction)],
update: [when(isTransactionEnable, TransactionManager.rollbackTransaction)],
patch: [],
remove: []
}
};
module.exports = moduleExports;
我收到此错误消息ReferenceError: when is not defined
。我删除了“何时”,交易仍然没有工作。