w***@qq.com
w***@qq.com
  • 发布:2022-02-09 20:53
  • 更新:2022-02-11 18:06
  • 阅读:303

线上环境匿名函数调用db操作数据库为什么不执行

分类:uniCloud
one.server.push(event, function(message) {  
    db.collection('debug-log').add({  
        info:'message',  
        info_object:message  
    })  
    return 'message.Content'  
})

这段代码,我在本地测试,数据库是可以插入一条数据的。
但是发布到线上后,调用就无法插入数据,return的话是正常的……
db前面是没办法用await要求同步的,可能是这个函数是普通函数的问题。
我对匿名和回调也是一知半解,这个是我自己写的插件,不懂是怎么回事,请帮忙回复一下。
刚看了函数日记,有这些

2022-02-09T21:12:50.446Z "Your current request database.insertDocument is longer than 3s, it may be due to the network or your query performance | [cd0fa3b07ba35461cfa6b4f5ded11386-17ede9d2f2f_2]"  
2022-02-09T21:12:50.448Z "(node:8) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error"  
2022-02-09T21:12:50.448Z "(node:8) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code."
2022-02-09 20:53 负责人:DCloud_uniCloud_WYQ 分享
已邀请:
DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

你是不是并行执行了很多数据库操作?

  • w***@qq.com (作者)

    没有的。就只有这一个插入操作

    2022-02-10 17:42

  • DCloud_uniCloud_WYQ

    回复 w***@qq.com: 你如果没等待数据库操作执行完成就返回了,那样会有问题,相当于这个实例里面攒下了很多没发送出去的数据库请求。

    2022-02-10 17:46

w***@qq.com

w***@qq.com (作者)

await one.server.push(event,async function(message) {    
    await db.collection('debug-log').add({    
        info:'message',    
        info_object:message    
    })    
    return 'message.Content'    
})

暂时只能这样子写代码了,太多修饰符了。

该问题目前已经被锁定, 无法添加新回复