我的mongoose collection中有这样一个字段
MemberMatches: [{ type: mongoose.Types.ObjectId, ref: 'Match'}],
当用户从match集合中删除匹配时,我想从这个数组中删除ObjectId。匹配的ID是从react前端到我的节点后端,在我的路由中,这是我到目前为止所尝试的
const deletedMatch = await MatchRegister.remove({_id: id}) (//remove the match from match collection)
const member = await findamember(name) (find the member using member name from member collection)
const newMatchArray1 = member.MemberMatches.filter(match => match.id !== id)
(filter the array based on the id coming from the front end)
const deletedMember = Member.findOneAndUpdate({MemberName: name}, {$push: {MemberMatches: newMatchArray1}}) (command to rewrite the MemberMatches array back)
最后一行不起作用。谁能给我指个正确的方向?
我明白了。命令是$set而不是$push,现在它可以工作了。由于