小程序云函数request请求_微信小程序调用云函数报错Db or Table not exist

  • Post author:
  • Post category:小程序


调用失败 Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID 6885a8c3-7483-11ea-9a3c-525400c7e4d7, cloud function service error code -504002, error message errCode: -502005 database collection not exists | errMsg: [ResourceNotFound] Db or Table not exist. Please check your request, but if the problem cannot be solved, contact us.;

Error: errCode: -502005 database collection not exists | errMsg: [ResourceNotFound] Db or Table not exist. Please check your request, but if the problem cannot be solved, contact us.;

这个错让我头大了好久,云数据库中明明有那个表,删了再加也不对,难道遇到鬼了?!

偶然中灵光一闪,意识到会不会和云控制台的多个环境有关?于是在网上寻找答案,终于完美解决。解决方法如下:

如果云控制台有多个环境,在云函数中初始化的时候必须指定环境id,否则,默认用第一个环境,不管你在开发时指定的环境是哪个!也不管你的app.js中初始化的环境是哪个!

cloud.init({ 
  env: cloud.DYNAMIC_CURRENT_ENV
})

唉,感觉微信的坑好多。。。

我在开发中遇到的更多的坑都已经记录在easyDemo小程序中,希望我的demo能给你easy。我还会持续更新easyDemo,欢迎收藏。

0d0f113844cf7671a6078988ca0f7171.png