const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
const db = cloud.database()
let {
OPENID,
APPID,
UNIONID
} = cloud.getWXContext()
const {
cnetent,
openid,
avatarUrl,
nickName,
fileList
} = event
const {
data
} = await db.collection('data').where({
openid: OPENID
}).get()
if (data.length == 0) {
const {
_id
} = await db.collection('data').add({
data: {
cnetent,
openid,
avatarUrl,
nickName,
fileList,
type: '',
introduce: '',
gender: '',
city: '',
age: '',
status: 2
}
})
const date = await db.collection('data').doc(_id).get()
return {
data: date.data
}
} else {
if (fileList.length != 0) {
await cloud.deleteFile({
fileList: [data.fileList.url]
})
}
const update = await db.collection('data').doc(data.data._id).update({
data: {
cnetent,
openid,
avatarUrl,
nickName,
fileList,
type: '',
introduce: '',
gender: '',
city: '',
age: '',
status: 2
}
})
return {
data: update
}
}
}
在报错的那行打个断点把,看下data是什么就知道了
有哪个地方的代码写错了嘛,找不到_id