小程序云开发lookup连表查询怎么加where?
发布于 4 年前 作者 exiao 12125 次浏览 来自 官方Issues
const res = await db.collection('book_lend').where({
        user: wxContext.OPENID
      }).aggregate()
        .lookup({
          from: 'books',
          localField: 'isbn',
          foreignField: 'isbn',
          as: 'bookDetail',
        })
        .end()

以上代码会报错,‘collection().where().aggregate().lookup().end() is not a function ’,怎么写才对呢?

2 回复

要么这样collection().where().get()

要么这样collection().aggregate().lookup().end()

where()和aggregate()不能共存

where()最后接get()

aggregate()最后接end()


lookup使用match可以看官方示例

https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-server-api/database/aggregation/stages/lookup.html#%E6%8B%BC%E6%8E%A5%E8%A2%AB%E8%BF%9E%E6%8E%A5%E9%9B%86%E5%90%88%E7%9A%84%E5%AD%90%E6%9F%A5%E8%AF%A2

where换成match

回到顶部