IT星空
IT星空
  • 发布:2025-05-17 08:41
  • 更新:2025-05-17 09:08
  • 阅读:21

$cloudEnv_uid is not defined

分类:uniCloud

云对象内操作数据库想插入默认的用户ID报这个错误:
$cloudEnv_uid is not defined
云对象代码如下:

const db = uniCloud.database();  
const moneyTable = db.collection('user-money');  
module.exports = {  
    _before: function () { // 通用预处理器  

    },  
    /**  
     * 看广告获取金钱(单位:分)  
     */  
    lookadreward(){  
        moneyTable.add({  
            money: 10,  
            user_id: $cloudEnv_uid,  
            type: 1,  
            balance: 10  
        }).then((res)=>{  
            console.log(res)  
            return {  
               errCode: 0,  
               errMsg: '创建成功'  
            }  
        }).catch((err)=>{  
            return {  
               errCode: err,  
               errMsg: '创建失败'  
            }  
        })        
    }  
}
2025-05-17 08:41 负责人:无 分享
已邀请:
IT星空

IT星空 (作者) - 编程是我的业余爱好

测试如果换成
user_id: db.getCloudEnv('$cloudEnv_uid'),
依然报错:
Error: db.getCloudEnv is not a function

要回复问题请先登录注册