2***@qq.com
2***@qq.com
  • 发布:2023-03-19 15:44
  • 更新:2023-03-19 16:01
  • 阅读:195

uni-cloud-router下面db.collection(...).where(...).getTemp is not a function

分类:uniCloud

其他JQL调用都是正常使用的,唯独getTemp这个报错
const {
Service
} = require("uni-cloud-router");
const db = uniCloud.database()
const collectionName = 'goods-favorite'
const collection = db.collection(collectionName)
module.exports = class GoodsService extends Service {
async getGoodsDetail(data) {
const goods = db.collection('opendb-mall-goods').where({
_id: data.goods_id
}).getTemp()
const favorite = db.collection('goods-favorite').where({
goods_id: data.goods_id,
openid: data.openid
}).getTemp()
try {
const result = await db.collection(goods, favorite).get()
console.log(result)
return {
code: 200,
message: '获取详情成功',
result
}
} catch (err) {
return {
code: 500,
message: err,
data
}
}
}
async favoriteAddOrUpdate(data) {
const {
total
} = await collection.where({
openid: data.openid,
goods_id: data.goods_id
}).count()
try {
if (total > 0) {
// 删除收藏
await collection.where({
openid: data.openid,
goods_id: data.goods_id
}).remove()
} else {
// 新增收藏
await collection.add({
...data,
createTime: Date.now()
})
}
const {
data: list
} = await collection.where({
openid: data.openid,
goods_id: data.goods_id
}).get({
getOne: true
})
return {
code: 200,
message: total > 0 ? '取消收藏' : '收藏成功',
status: list.length ? true : false
}
} catch (err) {
return {
code: 500,
message: err
}
}

}  
async getFavoriteStatus(data) {  
    try {  
        const {  
            data: list  
        } = await db.collection(collectionName).where({  
            openid: data.openid,  
            goods_id: data.id  
        }).get()  
        return {  
            code: 200,  
            message: '获取状态成功',  
            status: list.length ? true : false,  
            list  
        }  
    } catch (err) {  
        return {  
            code: 500,  
            message: err  
        }  
    }  
}  

};

2023-03-19 15:44 负责人:无 分享
已邀请:
2***@qq.com

2***@qq.com (作者)

已找到方法处理

const dbJQL = uniCloud.databaseForJQL({ // 获取JQL database引用,此处需要传入云函数的event和context,必传  
            event: this.ctx.event,  
            context: this.ctx.context  
        })

要回复问题请先登录注册