请教老师 为什么这里会找不到collection
来源:5-10 博客卡片组件blog-card
初学者之一
2019-12-25
我按照老师的方法试过了,首先是不能通过tcprouter调用程序,返回的是null。
我就尝试了把tcprouter的部分注释掉,直接查询。
结果是
{"errorCode":1,"errorMessage":"user code exception caught","stackTrace":"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.;
at Object.returnAsCloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:6057:16)
at Object.checkError (/var/user/node_modules/wx-server-sdk/index.js:1400:23)
at Promise (/var/user/node_modules/wx-server-sdk/index.js:1468:33)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)"}
说是
Db or Table not exist
然后实际上是
这里有collection,也有数据
请教老师问题出在哪里?
谢谢
以下是代码
页面:
onLoad: function (options) {
this._loadGoodslist()
},
_loadGoodslist(){
wx.showLoading({
title: '加载中',
})
wx.cloud .callFunction({
name:'goods',
data:{
$url:'list',
start:0,
count:10,
}
}).then(res=>{
this.setData({
GoodsItem:this.data.GoodsItem.concat(res.result)
})
})
wx.hideLoading()
wx.stopPullDownRefresh()
},
云函数:
goods index.js
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const TcbRouter = require('tcb-router')
const db = cloud.database()
const goodsCollection = db.collection('goodsInfo')
// 云函数入口函数
exports.main = async (ev, context) => {
// const app = new TcbRouter({
// ev
// })
// app.router('list',async (ctx,next)=>{
// let goodsList = await goodsCollection.get().then(res=>{
// return res.data
// })
// ctx.body = goodsList
// })
// return app.serve()
let goodsList = goodsCollection.get().then(res=>{
return res.data
})
return goodsList
}
写回答
1回答
-
在这里增加云环境ID:
cloud.init({
env: 'xxxxxx'})
022019-12-25
相似问题