1***@qq.com
1***@qq.com
  • 发布:2022-09-20 17:28
  • 更新:2022-09-21 11:13
  • 阅读:186

请问uniCloudDB 怎么样查询同表关联的字段

分类:uniCloud

就是我有一个评论表,表里有评论,和对评论的回复,我想用前端组件uniCloudDB来获取评论以及评论的回复还有user表进行关联,

期望得到的返回是这样的,

[  
    {  
        "_id":"6329806ba874f000011be8a7",  
        "dynamic_id":"631efaf942d23500017a4259",  
        "user_id":[  
                "_id":"631841a9ebfd9b0001fb535e",  
                "avatar_file":{  
                },  
                "nickname":"煎饼侠"  
        ],  
        "comment_content":"哈哈哈",  
        "like_count":0,  
        "comment_type":1,  
        "reply_user_id":[  
            {  
                "_id":"631841a9ebfd9b0001fb535e",  
                "avatar_file":{  
                },  
                "nickname":"煎饼侠"  
            }  
        ],  
        "reply_comment_id":[  
             {  
            "_id":"",  
            "dynamic_id":"631efaf942d23500017a4259",  
            "user_id":[  
                {  
                    "_id":"631841a9ebfd9b0001fb535e",  
                    "avatar_file":{  

                    },  
                    "nickname":"煎饼侠"  
                }  
            ],  
            "comment_content":"牛牛真可爱。",  
            "like_count":7,  
            "comment_type":1,  
            "reply_user_id":[  

            ],  
            "reply_comment_id":null,  
            "comment_date":1663660497040,  
            "comment_ip":"127.0.0.1"  
        }  
         ],  
        "comment_date":1663664235084,  
        "comment_ip":"127.0.0.1"  
    }  
]

但是报错使用临时表联表查询时禁止出现重复表明

表结构是这样的:

"properties": {  
        "_id": {  
            "description": "存储文档 ID(文章 ID),系统自动生成"  
        },  
        "dynamic_id": {  
            "bsonType": "string",  
            "description": "动态ID,dynamic 表中的`_id`字段",  
            "foreignKey": "dynamic._id"  
        },  
        "user_id": {  
            "bsonType": "string",  
            "description": "评论者ID,参考`uni-id-users` 表",  
            "forceDefaultValue": {  
                "$env": "uid"  
            },  
            "foreignKey": "uni-id-users._id"  
        },  
        "comment_content": {  
            "bsonType": "string",  
            "description": "评论内容",  
            "title": "评论内容",  
            "trim": "end"  
        },  
        "like_count": {  
            "bsonType": "int",  
            "description": "评论喜欢数、点赞数"  
        },  
        "comment_type": {  
            "bsonType": "int",  
            "description": "回复类型: 0 针对文章的回复  1 针对评论的回复"  
        },  
        "reply_user_id": {  
            "bsonType": "string",  
            "description": "被回复的评论用户ID,comment_type为1时有效",  
            "foreignKey": "uni-id-users._id"  
        },  
        "reply_comment_id": {  
            "bsonType": "string",  
            "description": "被回复的评论ID,comment_type为1时有效",  
            "foreignKey": "comments._id"  
        },  
        "comment_date": {  
            "bsonType": "timestamp",  
            "description": "评论发表时间",  
            "forceDefaultValue": {  
                "$env": "now"  
            }  
        },  
        "comment_ip": {  
            "bsonType": "string",  
            "description": "评论发表时 IP 地址",  
            "forceDefaultValue": {  
                "$env": "clientIP"  
            }  
        }  
    },
2022-09-20 17:28 负责人:无 分享
已邀请:
DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

你是想用树形查询吗?文档搜一下getTree

该问题目前已经被锁定, 无法添加新回复