mongoose 创建事务

2019-09-26  本文已影响0人  亦久亦韭

// const session = await mongoose.startSession();
// session.startTransaction();
try {
let hobbyItem = new SysHobbyModel({
'label': label,
'img': img
})
let hobby_id = hobbyItem['_id'];
let hobyyListItem = [];
item.forEach((ele) => {
let name = ele['name'];
let sys_language_id = ele['sys_language_id'];
let abb = ele['abb'];
hobyyListItem.push(
{
'hobby_id': hobby_id,
'sys_language_id': sys_language_id,
'abb': abb,
'name': name
}
)
});
// const opts = { session, new: true };
// const A = await hobbyItem.save(opts);
// const B = await SysHobbyListModel.insertMany(hobyyListItem, opts);
// await session.commitTransaction();
// session.endSession();

上一篇下一篇

猜你喜欢

热点阅读