uni-app unicloud-db 在支付宝云下 where无法使用db.command.exists false

uni-app unicloud-db 在支付宝云下 where无法使用db.command.exists false

操作步骤:

预期结果:

实际结果:

bug描述:

同代码下,unicloud-db在阿里云腾讯云下正常。

在支付宝云下
where参数:

type: db.command.or(
  db.command.exists(false), //不存在
  db.command.eq(0) // 等于 0
)

调试发现db.command.exists(false)没有效果,把type字段设置为int索引也没效果。


更多关于uni-app unicloud-db 在支付宝云下 where无法使用db.command.exists false的实战教程也可以访问 https://www.itying.com/category-93-b0.html

5 回复

我测试没有问题呢,我的测试数据: [
{ name: “1”, type: 0 },
{ name: “2”, type: 1 },
{ name: “3” }
] 查询语句: db.collection(‘test’).where({
type: db.command.or([
db.command.exists(false),
db.command.eq(0)
])
}).get() 结果: {“data”:[{"_id":“6875c9dfeee0dd702f64f621”,“name”:“1”,“type”:0},{"_id":“6875c9dfeee0dd702f64f623”,“name”:“3”}]}

更多关于uni-app unicloud-db 在支付宝云下 where无法使用db.command.exists false的实战教程也可以访问 https://www.itying.com/category-93-b0.html


得unicloud-db组件下,试试看?

你这没有中括号[],条件类型不对

我发现一个 BUG 前端使用 unicloud-db 组件,连接支付宝云数据库。然后前端动态修改 where 条件,不生效,总是使用首次的 where 条件。 请问如何解决?

如: 后续无论如何修改 where_forleave ,都不起作用
<unicloud-db ref="udb_forleave" collection="cy-lvshi-forleave-record" where="where_forleave" loadtime="manual" v-slot:default="{data,pagination,loading,error}" > </unicloud-db>

// this.where_forleave = ‘lvshi_userid==="${this.formDataId}" && forleave_date==="${item.appoint_date}"’ // this.where_forleave = ‘forleave_date==“2025-08-06”’ // this.where_forleave = item.appoint_date this.where_forleave = ‘forleave_date=="’ + item.appoint_date + ‘"’ console.log("this.where_forleave = " , this.where_forleave)
this.$refs.udb_forleave.loadData({} , datalist=>{
这里的 datalist ,总是首次 where 条件的记录。

在支付宝云环境下,db.command.exists(false) 确实存在兼容性问题。这是由于支付宝云(阿里云分支)对 MongoDB 操作符的支持与腾讯云/阿里云主服务存在差异。

解决方案:

  1. 改用 db.command.eq(null) 替代 db.command.exists(false)
type: db.command.or(
  db.command.eq(null), // 替代 exists(false)
  db.command.eq(0)
)
  1. 或者使用条件组合:
type: db.command.or([
  {type: null},
  {type: 0}
])
回到顶部