uni-app-x的云对象中,使用jql的.field会报错
uni-app-x的云对象中,使用jql的.field会报错
示例代码:
aaa(){
let db = uniCloud.database()
let user = db.collection('user')
let userRes = user.where({
cId: '65179d6f8620660127095068',
}).field('sex').get()
return userRes
}
这个是会报错的,field不管是什么字段,都报错,比如,
field('money')
就会报错Cannot assign to read only property ‘0’ of string ‘money’
以此类推
去掉.field就可以全部显示
操作步骤:
新建云对象user
输入代码
aaa(){
let db = uniCloud.database()
let user = db.collection('user')
let userRes = user.where({
cId: '65179d6f8620660127095068',
}).field('sex').get()
return userRes
}
uni-app-x
let user = uniCloud.importObject('user')
user.aaa()
报错
预期结果:
能正常筛选field
实际结果:
报错
bug描述:
云对象中,使用JQL,如果用field筛选列,会报错。
Possible Unhandled Promise Rejection:, UTSError(name='Error', message='Cannot assign to read only property '0' of string 'sex'', cause='null')
代码见代码示例
去掉.field就可以全部显示
云函数,uniappX客户端,datebase下的JQL查询都可以用field。
更多关于uni-app-x的云对象中,使用jql的.field会报错的实战教程也可以访问 https://www.itying.com/category-93-b0.html
日志忘记写了
前端
15:22:43.435 Possible Unhandled Promise Rejection:, UTSError(name=‘Error’, message=‘Cannot assign to read only property ‘0’ of string ‘sex’’, cause=‘null’)
15:22:43.582 10-12 15:22:42.686 1593 1647 I Timeline: Timeline: Activity_windows_visible id: ActivityRecord{bd6cc1 u0 io.dcloud.uniappx/io.dcloud.uniapp.appframe.activity.UniPageActivity t236} time:229131968
uniCloud
15:22:43.324 [本地调试][云对象:api]调用方法:[aaa],请求参数:无
15:22:43.333 [本地调试]TypeError: Cannot assign to read only property ‘0’ of string ‘sex’
15:22:43.333 [本地调试] at de.aaa (D:\HBuilderProjects\lieftUniappX\uniCloud-aliyun\cloudfunctions\api\index.obj.js:208:6)
15:22:43.333 [本地调试] at runMicrotasks (<anonymous>)
15:22:43.333 [本地调试] at processTicksAndRejections (node:internal/process/task_queues:96:5)
更多关于uni-app-x的云对象中,使用jql的.field会报错的实战教程也可以访问 https://www.itying.com/category-93-b0.html
别沉
1111
你用的不是jql语法,jql的db对象是uniCloud.databaseForJQL()方法获取的
知道了
你说的对,官方文档有点坑
这个报错是由于uni-app-x的云对象中对JQL的field方法处理存在bug导致的。从错误信息来看,系统尝试修改字符串’sex’的第0个字符,这显然是不合理的。
目前可以尝试以下两种临时解决方案:
- 使用传统云函数方式:
aaa(){
let db = uniCloud.database()
return db.collection('user')
.where({cId: '65179d6f8620660127095068'})
.field({sex: true})
.get()
}
- 或者改用字符串数组形式:
aaa(){
let db = uniCloud.database()
return db.collection('user')
.where({cId: '65179d6f8620660127095068'})
.field(['sex'])
.get()
}