【发布时间】:2021-01-03 20:24:25
【问题描述】:
我在 typescript 中有一个 nodejs 应用程序,我最近开始使用 mongoose 来查询 mongo db,但我正在努力寻找一种从 findById 方法获取类型化对象的方法。有没有办法通过某种方式从该方法中获取类型化对象?
import * as mongoose from 'mongoose';
export const LinksCacheSchema = new Schema({
ts: {
type: Date,
default: Date.now()
},
imdbId: String,
parentLink: String,
playableLink: String,
status: String,
title: String,
size: Number,
contentType: String,
}, { collection: 'links_cache' });
export const LinksCacheList = mongoose.model('LinksCache', LinksCacheSchema);
const linkInfo = await LinksCacheList.findById(documentId); //this is the one returning type of any instead of LinksCacheSchema or any specific type
【问题讨论】:
标签: node.js mongodb typescript mongoose mongoose-schema