// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
const rp = require('request-promise')
const URL = 'http://musicapi.xiecheng.live/personalized'
const platlistCollection = db.collection('platlist')
// 云函数入口函数
exports.main = async (event, context) => {
const list = await platlistCollection.get()
const playlist = await rp(URL).then((res)=>{
return JSON.parse(res).result
})
const newData = []
for(let i=0, len1 = playlist.length; i < len1; i++) {
let flag = true
for(let j=0, len2 = list.data.length; j < len2; j++){
if(playlist[i].id === list.data[j].id) {
flag = false
break
}
}
if(flag){
newData.push(playlist[i])
}
}
for (let i = 0, len = newData.length; i < len; i++){
await platlistCollection.add({
data:{
...newData[i],
createTime: db.serverDate(),
}
}).then((res)=>{
console.log('插入成功')
}).catch((err)=>{
console.log('插入失败')
})
}
return newData.length
}
调用状态
失败, ret code 1
返回结果
{“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.; "}
调用日志
START RequestId: 5196389e-ca04-11e9-b30a-525400e24e59
Event RequestId: 5196389e-ca04-11e9-b30a-525400e24e59
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.;
查了下错误码是无权限操作数据库,微信登录的账号也一直是我的,想问下是什么问题