云开发多表联合查询的问题
发布于 5 年前 作者 nafu 15069 次浏览 来自 问答
  • 不知道算不算bug,在get数据库后的then里面在根据查询的sid查询另一张表,把数据放到原来的属性,但无法访问到。

文章列表与文章评论,根据文章列表id查询评论数或评论,想过用云函数,但云函数调用次数担心有超出,所以想请教一下有没有其他方法

db.collection('article')
      .where({
        ispublic: true
      })
      .limit(16)
      .get()
      .then(res => {
        res.data.forEach((item, index) => {
          db.collection('commit')
            .where({
              sid: item._id
            })
            .count()
            .then(comitres => {
              item.commitNum = comitres.total
              return item
            })
          return item
        })
        console.info("111", res) //这里控制台输出能看到commitNum 属性
 
        return res
      })
      .then(rres => {
        console.info("最终返回的数据", rres) //这里控制台输出能看到commitNum 属性,但视图层没更新
        this.setData({
             lists: rres.data
        })
      })
6 回复

你好,现在提供的服务只有 NoSQL 数据库,无法进行多表 join,确实只能分多次查询。

如果担心调用次数超限,可以在这里申请提升配额:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference/quota.html

希望同时查询两张表的数据,

希望同时查询两张表的数据!!!!!!!!!

现在可以了吗

这个问题真的很重要啊,一般都是多表查询。希望快点解决。

希望提供多表联合查询的能力,或者提高数据库查询配额

回到顶部