mongodb 已经连接上数据库 操作增删改查 操作 什么情况下会出错
这代码… 都是 async 了,为啥里面还一堆的 then…
insert 的出错,那就看 mongo 那边咯,譬如主键重复,表不存在之类的。
@atian25 async 和 promise 这样写有问题吗? 有什么更好的写法?
await collection.insert
问题都解决了 代码优化过了
既然 await 了,就不应该有 then 什么的了
async function() { const result = await Promise.resolve('test').then(str => { return `hi, ${str}`; }).catch(err) { console.log(err); return `fail`; } return result; } async function() { let result; try { result = await Promise.resolve('test'); result = `hi, ${result}`; } catch(err) { console.log(err); result = `fail`; } return result; }
自己 hack collection.insert 故意让它出错。
好久之前写过一阵测试- -看了一下好像用muk这个库的 楼主可以看一下
@koroshi 自动化测试工具我有的 我上面是问怎么才能出现mongodb的错误因为不会人为的写bug所以才问的
问题已经解决了
CNode 社区为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。
这代码… 都是 async 了,为啥里面还一堆的 then…
insert 的出错,那就看 mongo 那边咯,譬如主键重复,表不存在之类的。
@atian25 async 和 promise 这样写有问题吗? 有什么更好的写法?
await collection.insert
问题都解决了 代码优化过了
既然 await 了,就不应该有 then 什么的了
自己 hack collection.insert 故意让它出错。
好久之前写过一阵测试- -看了一下好像用muk这个库的 楼主可以看一下
@koroshi 自动化测试工具我有的 我上面是问怎么才能出现mongodb的错误因为不会人为的写bug所以才问的
问题已经解决了