使用猫鼬findByIdAndUpdate时拉不起作用

时间:2019-10-15 18:55:56

标签: node.js mongoose

你好,我正在尝试使用NodeJS +猫鼬 findByIdAndUpdate 从数组中拉出对象,但这在我的文档中不起作用。

{
    "_id" : ObjectId("5da5cbfa6917aef39d03879d"),
    "name" : "MyTeam",
    "user" : "5d95c9566917aef39dfec8e3",
    "network" : [ 
        "5da59cc6e74b96292ce0c8a9", 
        "5da59caee74b96292ce0c8a8"
    ]
}

这是我尝试过的一系列代码,但是没有用。

第一

const result = await Teams.findByIdAndUpdate('5da5cbfa6917aef39d03879d',
{
    $pull: {
      network: '5da59cc6e74b96292ce0c8a9'
    }
}, { returnNewDocument: false })

console.log(result)

第二

const result = await Teams.findByIdAndUpdate('5da5cbfa6917aef39d03879d',
{
    $pull: {
      network: '5da59cc6e74b96292ce0c8a9'
    }
}, { returnOriginal: false })

console.log(result)

第三

const result = await Teams.findByIdAndUpdate('5da5cbfa6917aef39d03879d',
{
    $pull: {
      network: '5da59cc6e74b96292ce0c8a9'
    }
}, { new: true })

console.log(result)

第四

const result = await Teams.findByIdAndUpdate('5da5cbfa6917aef39d03879d',
{
    $pull: {
      network: '5da59cc6e74b96292ce0c8a9'
    }
}).exec()

console.log(result)

现在,请您帮我弄错哪里以及如何解决此问题?

0 个答案:

没有答案
相关问题