errCode: -502005 database collection not exists | errMsg: [ResourceNotFound] Db or Table not exist.

川长思鸟来 2022-12-04 07:57 297阅读 0赞

微信小程序云函数开发报错:

  1. Uncaught (in promise) thirdScriptError
  2. 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.
  3. 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.
  4. at new u (http://127.0.0.1:50148/appservice/__dev__/WAService.js:2:232879)
  5. at Function.success (http://127.0.0.1:50148/appservice/__dev__/WAService.js:2:283581)
  6. at Object.success (http://127.0.0.1:50148/appservice/__dev__/WAService.js:2:126419)
  7. at y (http://127.0.0.1:50148/appservice/__dev__/WAService.js:2:528980)
  8. at v (http://127.0.0.1:50148/appservice/__dev__/WAService.js:2:529218)
  9. at http://127.0.0.1:50148/appservice/__dev__/WAService.js:2:530772
  10. at n.<anonymous> (http://127.0.0.1:50148/appservice/__dev__/asdebug.js:1:10293)
  11. at http://127.0.0.1:50148/appservice/__dev__/WAService.js:2:126419
  12. at http://127.0.0.1:50148/appservice/__dev__/WAService.js:2:109342
  13. console.error @ VM1199:1
  14. errorReport @ VM1206 WAService.js:2
  15. thirdErrorReport @ VM1206 WAService.js:2
  16. (anonymous) @ VM1206 WAService.js:2
  17. c @ VM1206 WAService.js:2
  18. i @ VM1206 WAService.js:2
  19. (anonymous) @ VM1206 WAService.js:2
  20. value @ VM1206 WAService.js:2
  21. t @ VM1206 WAService.js:2
  22. (anonymous) @ VM1206 WAService.js:2

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.

错误原因1:数据库没有对应的集合

那么问题来了,错误提示中并没有提示具体那一个集合没有,这时候我们可以去代码中找有哪些集合,微信开发者工具中全局搜“collection”

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L21laW1laWVlZQ_size_16_color_FFFFFF_t_70

然后打开开发工具的云开发,在云数据库中全部添加对应的集合

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L21laW1laWVlZQ_size_16_color_FFFFFF_t_70 1

错误原因2:云函数与数据库没在一个环境

你有可能有两个云开发环境

  1. if (!wx.cloud) {
  2. console.error('请使用 2.2.3 或以上的基础库以使用云能力')
  3. } else {
  4. wx.cloud.init({
  5. // 此处请填入环境 ID, 环境 ID 可打开云控制台查看
  6. env: '321',
  7. traceUser: true
  8. })
  9. }
  10. }

但是在云函数里用的却是默认的初始化。

  1. const cloud = require('wx-server-sdk')
  2. cloud.init()
  3. const db = cloud.database()
  4. exports.main = async(event, context) => {
  5. try {
  6. return await db.collection('busers').add({
  7. data: {
  8. year: event.year,
  9. month: event.month
  10. }
  11. })
  12. }catch(e){
  13. console.error(e)
  14. }
  15. }

发表评论

表情:
评论列表 (有 0 条评论,297人围观)

还没有评论,来说两句吧...

相关阅读