草庐IT

node.js - 在预保存 Hook 中更新

我有这样的用户模式constuserSchema=newSchema({username:{type:String,unique:true,required:true,},cardIds:[{type:Schema.Types.ObjectId,ref:'cards',}],})mongoose.model('users',userSchema)我试图在用户的预保存Hook中做两件事:首先,使用用户ID保存每张卡,其次,将cardIds添加到用户。我的代码:constCard=mongoose.model('cards')userSchema.pre('save',function(n