heiheiha
heiheiha
  • 发布:2022-07-01 10:59
  • 更新:2022-07-04 11:48
  • 阅读:467

【报Bug】云函数和本地运行结果不一致

分类:uniCloud

产品分类: uniCloud/App

操作步骤:

通过开发客户端分别 本地调用和云端调用

预期结果:

调用结果一致,均插入数据

实际结果:

云端运行结果
10:46:49.777 [阿里云:app-workday]正在上传云函数testFnc(已携带testFnc.param.json参数)...
10:46:53.100 [云端运行:阿里云:app-workday]云函数testFnc上传完成,开始运行...
10:47:10.612 [云端运行:阿里云:app-workday]运行状态:成功
10:47:10.612 [云端运行:阿里云:app-workday]返回结果:0
10:47:10.612 [云端运行:阿里云:app-workday]运行日志:

本地运行结果
10:48:47.867 [本地运行:阿里云:app-workday]运行日志:
10:48:47.876 [本地运行:阿里云:app-workday]本地运行云对象【testFnc】...
10:48:49.754 [本地运行]"[云对象:testFnc],调用方法:[test],执行结果:" 0
10:48:49.924 [本地运行]"addRes:" {"id":"62be60917696a800014cdd10"} uniCloud-aliyun/cloudfunctions/testFnc/index.obj.js:17:11
10:48:49.930 [本地运行]"addRes:" {"id":"62be60919d207000018787d8"} uniCloud-aliyun/cloudfunctions/testFnc/index.obj.js:17:11

bug描述:

这段往数据库插入数据,在本地运行没有问题,在服务器端运行,无法插入数据

    // 开发文档: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj  

    const db = uniCloud.database(); //代码块为cdb  

    const hosCollection = db.collection('ti_hospital')  

    module.exports = {  
        test(){  
            let arr = [3,2]   
            let init = 0  

            arr.forEach(async n => {  

                let res = await hosCollection.add({  
                    'hospital_name': 'test_' + n  
                })  
                console.log('addRes:', res)  

                init += n   
            })  

            return init  
        }  
    }  
2022-07-01 10:59 负责人:无 分享
已邀请:
DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

阿里云、腾讯云nodejs8在云函数return之后其余逻辑会被冻结不再执行。你把forEach换成for循环即可得到你想要的效果

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