uni-app 阿里云updateAndReturn若更新内容为空对象不会报错会直接覆盖原对象

uni-app 阿里云updateAndReturn若更新内容为空对象不会报错会直接覆盖原对象

示例代码:

db.collection('test').doc("_id").updateAndReturn({})

操作步骤:

db.collection('test').doc("_id").updateAndReturn({})

预期结果:

报错update field should not be an empty object

实际结果:

原对象直接被覆盖

bug描述:

阿里云updateAndReturn若更新内容为空对象不会报错,会直接覆盖原对象


更多关于uni-app 阿里云updateAndReturn若更新内容为空对象不会报错会直接覆盖原对象的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

HBuilderX 4.61.2025040322-alpha 已修复。

更多关于uni-app 阿里云updateAndReturn若更新内容为空对象不会报错会直接覆盖原对象的实战教程也可以访问 https://www.itying.com/category-93-b0.html


已确认问题,下版本修复。

这是一个需要注意的阿里云数据库行为差异问题。在uni-app中使用阿里云数据库服务时,updateAndReturn方法对空对象的处理确实与预期不符。

当传入空对象{}时,阿里云数据库不会抛出"update field should not be an empty object"的错误,而是会执行更新操作,这可能导致数据被意外覆盖。

建议在使用updateAndReturn前,手动检查更新对象是否为空:

if(Object.keys(updateData).length === 0) {
    throw new Error('update field should not be an empty object');
}
回到顶部