我正在尝试更新后端应用程序中的架构(使用 node/express/typescript),但是当我执行 .save() 时它会中断,因为类型不像 type
它是 {{1} }
并且在我的应用程序中发生以下错误
type[]
这是架构
Property 'save' does not exist on type 'Ipub[]'
这是schema的界面
import { Schema, model } from "mongoose";
import { Ipub } from "../helpers/PublicationInterfaces";
const publication = new Schema<Ipub>({
body: { type: String },
photo: { type: String },
creator: {
name: { required: true, type: String },
perfil: { type: String },
identifier: { required: true, type: String }
},
likes: [
{
identifier: { type: String }
}
],
comments: [
{
body: { type: String },
name: { type: String },
perfil: { type: String },
identifier: { type: String },
createdAt: { type: Date, default: new Date() },
likesComments: [
{
identifier: { type: String }
}
]
}
],
createdAt: { required: true, type: Date, default: new Date() }
});
export default model("Publications", publication);
这是代码中断的地方,看看我放置 await updateSub.save() 的代码行
import { Document } from "mongoose";
// Publication's representation
export interface Ipub extends Document {
body: string;
photo: string;
creator: {
name: string;
perfil?: string;
identifier: string;
};
likes?: [
{
identifier: string;
}
];
comments?: [
{
body: string;
name: string;
perfil: string;
identifier: string;
createdAt: Date;
likesComments: [
{
identifier: string;
}
];
}
];
createdAt: Date;
}
真的很奇怪,看起来是因为 Ipub[] 类型定义,我该怎么办!
感谢您的帮助!