小编Noo*_*ish的帖子

Nestjs:如何使用mongoose启动会话进行交易?

使用事务的 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)

mongoose nestjs

9
推荐指数
2
解决办法
9442
查看次数

html5/Javascript - 如何获取Selected文件夹名称?

我正在使用webkitdirectory来选择一个文件夹.我想获取选择上传的文件夹名称.

javascript html5

8
推荐指数
1
解决办法
2万
查看次数

使用ui-sref传递数据属性

我想从控制器传递一些额外的数据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)

我想要imgNameimgDesc进入控制器.我已经检查$state但是没有找到它.有什么办法吗?

angularjs angular-ui-router ui-sref

3
推荐指数
1
解决办法
4605
查看次数