收藏
回答

云函数本地调试无法操作数据库?

node.js:1 [error] Unhandled Rejection at: Promise {<rejected>: CloudSDKError: errCode: -1 unknown error | errMsg: collection.get:fail Error: 

          400 Bad Req…}__proto__: Promise[[PromiseStatus]]: "rejected"[[PromiseValue]]: CloudSDKError: errCode: -1 unknown error | errMsg: collection.get:fail Error: 

          400 Bad Request

        ; at collection.get api; 

    at returnAsCloudSDKError (C:\Users\Administrator\WeChatProjects\miniprogram-3\cloudfunctions\obj\node_modules\wx-server-sdk\index.js:6086:16)

    at Object.returnAsFinalCloudSDKError (C:\Users\Administrator\WeChatProjects\miniprogram-3\cloudfunctions\obj\node_modules\wx-server-sdk\index.js:6100:15)

    at Promise (C:\Users\Administrator\WeChatProjects\miniprogram-3\cloudfunctions\obj\node_modules\wx-server-sdk\index.js:1472:32)

    at processTicksAndRejections (internal/process/task_queues.js:86:5)errCode: -1errMsg: "collection.get:fail Error: ↵          400 Bad Request↵        ; at collection.get api; "message: (...)stack: "Error: errCode: -1 unknown error | errMsg: collection.get:fail Error: ↵          400 Bad Request↵        ; at collection.get api; ↵    at returnAsCloudSDKError (C:\Users\Administrator\WeChatProjects\miniprogram-3\cloudfunctions\obj\node_modules\wx-server-sdk\index.js:6086:16)↵    at Object.returnAsFinalCloudSDKError (C:\Users\Administrator\WeChatProjects\miniprogram-3\cloudfunctions\obj\node_modules\wx-server-sdk\index.js:6100:15)↵    at Promise (C:\Users\Administrator\WeChatProjects\miniprogram-3\cloudfunctions\obj\node_modules\wx-server-sdk\index.js:1472:32)↵    at processTicksAndRejections (internal/process/task_queues.js:86:5)"get message: ƒ get()set message: ƒ set(msg)__proto__: Error reason: CloudSDKError: errCode: -1 unknown error | errMsg: collection.get:fail Error: 

          400 Bad Request

        ; at collection.get api; 

    at returnAsCloudSDKError (C:\Users\Administrator\WeChatProjects\miniprogram-3\cloudfunctions\obj\node_modules\wx-server-sdk\index.js:6086:16)

    at Object.returnAsFinalCloudSDKError (C:\Users\Administrator\WeChatProjects\miniprogram-3\cloudfunctions\obj\node_modules\wx-server-sdk\index.js:6100:15)

    at Promise (C:\Users\Administrator\WeChatProjects\miniprogram-3\cloudfunctions\obj\node_modules\wx-server-sdk\index.js:1472:32)

    at processTicksAndRejections (internal/process/task_queues.js:86:5)



// 云函数入口文件

const cloud = require('wx-server-sdk')

const rp = require('request-promise')

const fs = require('fs')

const path = require('path')

cloud.init({

env: 'jbd-test-6c456c'

})const db = cloud.database()

var url = require("url")

// 云函数入口函数

exports.main = async (event, context) => {

db.collection('objects').get({

success: function (res) {

// res.data 是一个包含集合中有权限访问的所有记录的数据,不超过 20 条

console.log(res.data)

}

})

}


代码为最简单的文档中给出的测试代码


package.json

{

"name": "obj",

"version": "1.0.0",

"description": "",

"main": "index.js",

"scripts": {

"test": "echo \"Error: no test specified\" && exit 1"

},

"author": "",

"license": "ISC",

"dependencies": {

"request-promise": "^4.2.5",

"wx-server-sdk": "^1.8.2"

}

}


回答关注问题邀请回答
收藏

2 个回答

  • 汤Cur
    汤Cur
    08-28

    我也这个情况,如果这是正常,为啥官网没有提呢?

    08-28
    有用
    回复
  • 大虎头
    大虎头
    03-03

    好像还有个类似的朋友

    https://developers.weixin.qq.com/community/develop/doc/000a22b8264e484ff6e93fa8d56400

    03-03
    有用
    回复 7
    • 咬人的圆白菜
      咬人的圆白菜
      03-19
      我也遇到了这个问题,你现在有解决了吗
      03-19
      回复
    • 大虎头
      大虎头
      03-20回复咬人的圆白菜
      解决了 云函数的执行环境问题 id已经要正确
      03-20
      回复
    • 大虎头
      大虎头
      03-20
      一定要正确
      03-20
      回复
    • 咬人的圆白菜
      咬人的圆白菜
      03-20回复大虎头
      那可能我不是这个问题了,我的环境id和cloud.DYNAMIC_CURRENT_ENV都试了一遍,还是这个情况。。。
      03-20
      回复
    • 大虎头
      大虎头
      03-20回复咬人的圆白菜
      我开始也是这么认为的,折腾了一个下午,最后就是这个问题,我重新打了一遍代码...反正就是神奇的
      03-20
      回复
    查看更多(2)
登录 后发表内容
问题标签