0
点赞
收藏
分享

微信扫一扫

Node Mongodb 删除数组中的对象

爱读书的歌者 2023-04-01 阅读 95


使用 $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,
                    },
                },
            }
        );


举报

相关推荐

0 条评论