Node.js 如果评论不';他们没有自己的模型吗?

Node.js 如果评论不';他们没有自己的模型吗?,node.js,mongoose,Node.js,Mongoose,因此,我试图找出如何删除用户对mongoose的评论,但我不确定如何删除,但主要是因为我的应用程序上的评论没有自己的模型 如果我真的想这样做,我会给出他们自己的模型的注释,但我想保持我的模式不变。因此,我的PostSchema如下所示: const PostSchema = new Schema({ user: [ { type : mongoose.Schema.ObjectId, ref : 'users' } ],

因此,我试图找出如何删除用户对mongoose的评论,但我不确定如何删除,但主要是因为我的应用程序上的评论没有自己的模型

如果我真的想这样做,我会给出他们自己的模型的注释,但我想保持我的模式不变。因此,我的PostSchema如下所示:

const PostSchema = new Schema({
    user: [ 
        {
            type : mongoose.Schema.ObjectId, ref : 'users'
        } 
    ],
    text: {
        type: String,
        required: true
    },
    name: {
        type: String
    },
    likes: [
        {
            user: {
                type: Schema.Types.ObjectId,
                ref: 'users'
            }
        }
    ],
    comments: [
        {
            user: {
                type: Schema.Types.ObjectId,
                ref: 'users'
            },
            text: {
                type: String,
                require: true
            },
            name: {
                type: String
            },
            date: {
                type: Date,
                default: Date.now
            }
        }


    ],
    date: {
        type: Date,
        default: Date.now 
    }

}); 

我想能够删除所有用户的评论,但不是帖子。这是可以做到的,还是唯一的方法是创建一个评论模型,并为其提供一对多关系?

以下内容将从每篇文章中删除用户的评论

MyPostModel.updateMany({}, { $pull: { comments: { user: userIdToRemove } } });