1

我正在尝试在我的应用程序中使用@casl/mongoose 和 mongoose - paginate-v2express.js,但问题是必须在model对象上使用两个库。

  // trying this
  const results = await Person
      .accessibleBy(req['ability'])
      .paginate({}, options);

  // or this, the same problem
  const results = await Person
      .paginate({}, options)
      .accessibleBy(req['ability']);

在这两种方式中,我都得到了accessibleBy/paginate不是一个函数,因为正如我所说的,两个库都必须在模型(在我的情况下Person)对象上使用。

非常感谢任何帮助或建议。

4

1 回答 1

2

@casl/mongoose支持 mongoose 的静态和查询方法。所以,你可以这样做:

Person.findOne({ _id: id }).accessibleBy(ability).where({ createdAt: { $lt: new Date() } })

// or
Person.accessibleBy(ability).findOne({ _id: id }).where({ createdAt: { $lt: new Date() } })

同时分页插件仅支持静态方法,因为它向数据库发送多个查询,因此(可能)无法实现您想要的。要么和那个包的作者谈谈,让他用那个来做点什么,要么只写自己的分页插件

于 2021-09-21T05:21:46.650 回答