gpt4 book ai didi

node.js - mongodb 尝试删除可能不存在的集合

转载 作者:太空宇宙 更新时间:2023-11-04 01:26:16 25 4
gpt4 key购买 nike

我得到:

(node:78465) UnhandledPromiseRejectionWarning: MongoError: ns not found

我的代码:

  delete(projectId) {
if (!this.db) return
this.db.collection(projectId, (err, collection) => {
// err is null here.
collection.drop();
});
}

如果集合不存在,如何确保不会收到错误消息。

最佳答案

使用 promise :

this.db.collection(projectId).drop().then(function () {
// success
}).catch(function () {
// error handling
})

关于node.js - mongodb 尝试删除可能不存在的集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57434623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com