返回mongoose文档类型脚本

e0bqpujr  于 2022-11-24  发布在  Go
关注(0)|答案(1)|浏览(109)

我尝试返回mongoose文档,但随后我得到这个错误:
类型'(个人文档& { _id:ObjectId; })[]'遗漏型别' IPersonDocument '的下列属性:名字、姓氏、组、$assertPopulated和其他52个.ts(2740)
IPersonDocument是IPersonMongoose.Document的扩展
这是我代码:
repo.ts

export async function findByName(name: String): Promise<IPersonDocument>{
    return await PersonsModel.find({ firstName: name }) //problem here
}

type.ts

import { Document, Model } from "mongoose";

export interface IPerson {
    firstName: string;
    lastName: string;
    age?: number;
    email?: string,
    groups: [String],
    dateOfEntry?: Date;
}

export interface IPersonDocument extends IPerson, Document { }

export interface IPersonModel extends Model<IPersonDocument> { }

moduel.ts

import { model } from "mongoose";
import { IPersonDocument } from "../../../type/person.types";
import PersonsSchema from "./person.schema";

export const PersonsModel = model<IPersonDocument>("persons", PersonsSchema)
pcww981p

pcww981p1#

添加倾斜()
返回等待人员模型。查找({名字:名称}).lean();
它将DOC对象转换为js对象。

相关问题