使用事务的 mongoose 文档很简单,但是当在 Nestjs 中遵循它时,它会返回一个错误:
Connection 0 was disconnected when calling `startSession`
MongooseError: Connection 0 was disconnected when calling `startSession`
at NativeConnection.startSession
Run Code Online (Sandbox Code Playgroud)
我的代码:
const transactionSession = await mongoose.startSession();
transactionSession.startTransaction();
try
{
const newSignupBody: CreateUserDto = {password: hashedPassword, email, username};
const user: User = await this.userService.create(newSignupBody);
//save the profile.
const profile: Profile = await this.profileService.create(user['Id'], signupDto);
const result:AuthResponseDto = this.getAuthUserResponse(user, profile);
transactionSession.commitTransaction();
return result;
}
catch(err)
{
transactionSession.abortTransaction();
}
finally
{
transactionSession.endSession();
}
Run Code Online (Sandbox Code Playgroud) 我正在使用webkitdirectory来选择一个文件夹.我想获取选择上传的文件夹名称.
我想从控制器传递一些额外的数据ui-sref.我循环一个json对象并将数据添加到sref:<a data-imgName="{{ img.name }}" data-imgDesc="{{ img.desc }}" ui-sref="main.imgDesc({imgid: '{{ img.id }}'})">
$stateProvider.state('main.imgDesc', {
url: '/image/:imgid',
templateUrl: '...',
controller: 'ImageDescCtrl'
});
Run Code Online (Sandbox Code Playgroud)
我想要imgName并imgDesc进入控制器.我已经检查$state但是没有找到它.有什么办法吗?