相关疑难解决方法(0)

(mongoose/promises)如何检查文档是否是使用带有upsert的findOneAndUpdate创建的

考虑这段代码,我需要创建或更新特定文档.

Inbox.model.findOneAndUpdate({ number: req.phone.number }, {
    number: req.phone.number,
    country: req.phone.country,
    token: hat(),
    appInstalled: true
}, { new: true, upsert: true }).then(function(inbox){
    /*
       do something here with inbox, but only if the inbox was created (not updated)
    */
});
Run Code Online (Sandbox Code Playgroud)

mongoose是否有能力区分是否创建或更新了文档?我需要new: true因为我需要调用函数inbox.

mongoose mongodb node.js promise mongodb-query

5
推荐指数
1
解决办法
2042
查看次数

标签 统计

mongodb ×1

mongodb-query ×1

mongoose ×1

node.js ×1

promise ×1