使用 $pull 删除
要求传入的对象必须和数据库中的对象一致
import { ObjectId, Double } from "mongodb";
const delSelfFromFriendList = await db.collection("userInfo").updateOne(
{ _id: new ObjectId(req.body.friendItem.friendId) },
{
$pull: {
friendsList: {
date: new Double(req.body.friendItem.date),
friendId: req.body.userId,
chatRecordId: req.body.friendItem.chatRecordId,
},
},
}
);