我正在尝试转换mongoose.Model.find(..)的结果。使用rxjs.from()添加到可观察对象。
我正在使用Typegoose,但我无法将.find的结果转化为承诺
MyClassModel.find({}) as Promise<MyClass>我得到了TS错误:将类型'DocumentQuery,InstanceType,{}>‘转换为类型'Promise’可能是一个错误,因为两种类型都不能完全重叠。如果这是故意的,请先将表达式转换为“未知”。
我找不到解决方案。我也试过了:
MyClassModel.find({}) as Promise<DocumentQuery<InstanceType<MyCLass>, InstanceType<MyClass>>但没那么走运。
有人试过这个吗?
发布于 2019-05-06 11:38:17
查询不是承诺。https://mongoosejs.com/docs/promises.html#queries-are-not-promises
它们有.then功能,但并不是完全的承诺。如果需要promise,请调用.exec命令。
MyClassModel.find({}).exec()https://stackoverflow.com/questions/54981088
复制相似问题