【发布时间】:2021-09-17 01:20:53
【问题描述】:
我正在尝试创建一个新的 mongo 对象,但下面的代码返回一个只有 id 的空对象。我做错了什么,我只是看不到错误。调用时没有返回错误,只是一个空对象。 这是 Nest js 应用程序
const newComment = new this.commentModel({
name: user.name,
avatar: user.avatar,
user: userId,
text: text,
});
这是我的架构:
Schema();
class Comment {
@Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'User' })
user: User;
@Prop({ required: true })
text: string;
@Prop()
name: string;
@Prop()
avatar: string;
@Prop({ default: Date.now })
date: Date;
}
export const CommentSchema = SchemaFactory.createForClass(Comment);
谁能帮我解决这个问题?
【问题讨论】:
标签: typescript mongodb mongoose nestjs mongoose-schema