uni-app 支付宝云在修改时如果原字段是null则无法修改成功查询为null数据也无效
uni-app 支付宝云在修改时如果原字段是null则无法修改成功查询为null数据也无效
产品分类:
uniCloud/支付宝小程序云
示例代码:
// bug 1
db.collection('edu_question').where({
answer_video:dbCmd.eq(null)
}).field("_id,answer_video").get()
// bug2
db.collection(dbName).doc(_id).updateAndReturn({
title,
knowledge_id,
subject,
stage,
question_type,
question_content,
options,
correct_answer,
answer_image,
answer_video,
related_video_id,
difficulty,
status,
create_by,
create_time,
update_by,
update_time
});
// bug2 另外一种写法
db.collection('edu_question').doc("68cbad06d3f484b4ddc4e120").update({
"answer_video": {
"cloudPath": "1758516601487_0.mp4",
"extname": "mp4",
"fileID": "cloud://env-ttttttttt/1/2/68d0d163a0bcbf02418ddd65/q/06832579362276925_1758516601490_0.mp4",
"fileType": "video",
"name": "这个题目没有上传.mp4",
"path": "https://env-ttttttt.normal.cloudstatic.cn/1/2/68d0d163a0bcbf02418ddd65/q/06832579362276925_1758516601490_0.mp4?expire_at=1758517201&er_sign=32430614eb59ccb8a4c1366349da9f31",
"size": 1317328,
"status": "success",
"url": "https://env-ttttttt.normal.cloudstatic.cn/1/2/68d0d163a0bcbf02418ddd65/q/06832579362276925_1758516601490_0.mp4?expire_at=1758517201&er_sign=32430614eb59ccb8a4c1366349da9f31",
"uuid": 1758516601488
}
)
// 修改后,answer_video 依然是null
// 提示信息为 更新完成,更新条数为0,请求耗时...
操作步骤:
如图所示
预期结果:
如图所示
实际结果:
如图所示
bug描述:
前提:
字段answer_video 为Object类型
BUG1 :
查询某个字段为null的数据,结果查询出所有数据
db.collection('edu_question').where({
answer_video:dbCmd.eq(null)
}).field("_id,answer_video").get()
BUG2:
使用update修改时,如果某个数据(answer_video)在修改前的值是null, 那么无论如何都无法修改成功。


更多关于uni-app 支付宝云在修改时如果原字段是null则无法修改成功查询为null数据也无效的实战教程也可以访问 https://www.itying.com/category-93-b0.html
你是不是动过索引,我之前也遇到了无法改动的数据,最后厂商说是索引异常
更多关于uni-app 支付宝云在修改时如果原字段是null则无法修改成功查询为null数据也无效的实战教程也可以访问 https://www.itying.com/category-93-b0.html
没有动过的,如果先设置一个默认值,再去修改,就是可以的。
这是一个支付宝小程序云数据库的已知问题,主要涉及对null值的处理。
问题分析:
-
查询null值异常:
dbCmd.eq(null)在支付宝云中无法正确匹配null字段,导致查询条件失效,返回所有数据。 -
更新null字段失败:当字段原始值为null时,update操作无法成功修改该字段,返回更新条数为0。
解决方案:
针对查询问题: 使用云函数进行查询,在云函数中使用MongoDB原生语法:
// 云函数中
db.collection('edu_question').where({
answer_video: null
}).field("_id,answer_video").get()
针对更新问题:
- 方案一:使用云函数更新
// 在云函数中执行update
db.collection('edu_question').doc("68cbad06d3f484b4ddc4e120").update({
answer_video: yourVideoObject
})
- 方案二:使用replace操作 如果update持续失败,可尝试使用replace替换整条记录:
const record = await db.collection('edu_question').doc(_id).get()
const data = record.data[0]
// 更新需要修改的字段
data.answer_video = yourVideoObject
// 替换整条记录
await db.collection('edu_question').doc(_id).set(data)

