V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
xiaohantx
V2EX  ›  问与答

uniCloud JQL 查询使用问题

  •  
  •   xiaohantx · 86 天前 · 437 次点击
    这是一个创建于 86 天前的主题,其中的信息可能已经有所发展或是发生改变。
    post user
    _id _id
    title nickName
    content
    author

    我需要返回 post 表所有内容并且根据 post 表的 author 字段去查 user 表的_id 字段,并把 nickname 单独这个字段拼到 post 查询结果里返回回来

    db.collection('post')
        .aggregate()
        .lookup({
            from: 'uni-id-users',
            localField: 'author',
            foreignField: '_id',
            as: 'authorNickName'
        }).match({
            authorNickName: {
                title: '用户名'
            }
        }).end()
    

    我看着是关联查询但是好像没办法查询起来,我看文档还有提到 pipeline ,我需要用到这个东西吗。。

    xiaohantx
        1
    xiaohantx  
    OP
       86 天前
    看了下采用了这个

    ```
    let postTemp = await db.collection('post').field("title,content,author").getTemp()
    let userTemp = await db.collection('uni-id-users').field("_id,nickName").getTemp()
    let postResult = await db.collection(postTemp, userTemp).get()
    ```


    但是一直在报错,不知道啥原因。。。

    ```
    { "code": "INVOKE_FUNCTION_FAILED", "message": "Cannot assign to read only property '0' of string 'title,content,author'", "stack": "TypeError: Cannot assign to read only property '0' of string 'title,content,author'\n at qt.field (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/unicloud/aliyun/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:41743)\n at Proxy.getPost (/Users/han/Coding/hotPot/xxxxx/uniCloud-aliyun/cloudfunctions/client/controller/post.js:31:42)\n at a (/Users/han/Coding/hotPot/xxxxx/uni_modules/uni-cloud-router/uniCloud/cloudfunctions/common/uni-cloud-router/dist/index.js:1:9940)\n at i (/Users/han/Coding/hotPot/xxxxx/uni_modules/uni-cloud-router/uniCloud/cloudfunctions/common/uni-cloud-router/dist/index.js:1:6247)\n at auth (/Users/han/Coding/hotPot/xxxxx/uniCloud-aliyun/cloudfunctions/client/middleware/checkToken.js:21:9)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)\n at async R (/Users/han/Coding/hotPot/xxxxx/uni_modules/uni-cloud-router/uniCloud/cloudfunctions/common/uni-cloud-router/dist/index.js:1:7655)"}
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1010 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 18:31 · PVG 02:31 · LAX 11:31 · JFK 14:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.