数据库条件参数问题,数据字段为参数时?
发布于 5 年前 作者 libai 11012 次浏览 来自 问答

    var Result = await db.collection(‘UserData’).where({

          _id:Target_openId ,

          ‘trees.3’ : 5

    }).update({

      data:{

        score : _.inc(-1)

      }

    })

这样写,没问题。

换成如下

let idx = ‘\‘trees.3\’’

    var Result = await db.collection(‘UserData’).where({

          _id:Target_openId ,

          idx : 5

    }).update({

      data:{

        score : _.inc(-1)

      }

    })

这样就写,就完全不行了。但是这个idx里的往往是需要外部确认的,函数内部并不知道外部需要通过数组的第几个元素为判断的。

希望官方可以解决下

2 回复

没看懂你在说啥?是动态参数吗?

let idx = 'tree.3'

where({
  [idx]: 5
})

不然的话只有重复写如此的n个函数,只是trees.x 中的x值 有多少种,就得有多少个函数。真是鸟疼

回到顶部