我正尝试在我的express.js应用程序中使用@casl/mongoose和mongoose-paginate-v2,但问题是这两个库都必须在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)对象上使用。
任何帮助或建议都是非常感谢的。
发布于 2021-09-21 05:21:47
@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() } })同时,分页插件只支持静态方法,因为它会向数据库发送多个查询,所以(可能)不可能实现你想要的结果。要么与该包的作者交谈,让他使用该包做smth,要么直接编写自己的分页插件
https://stackoverflow.com/questions/69184297
复制相似问题