解析平台-如何仅基于指针查询

时间:2019-07-04 18:21:25

标签: javascript mongodb parse-platform

我正在构建一个具有回复功能的评论系统。创建父注释或主注释的人,我将其个人资料另存为一个指针,该指针是使用下面的这一行代码获取的     let myProfile: Parse.Object = await parentThread.get('profile').fetch(masterKey)

答复存储在此主线程下的数组结构中,答复基本上以相同的方式存储(请参见下面的结构)

parentComment = {
    threadID: string
    uid: string
    fullname: string
    photos: string
    comment: string
    replies: replyComment[]    
}


replyComment = {
    uid: string
    fullname: string
    photos: string
    comment: string
}

我可以毫无问题地获取顶级个人资料,但是在下面的地图中任何试图拉出/生成回复用户个人资料的尝试都证明是徒劳的 一旦有了指针,有没有更简单的方法来访问数据?

用户个人资料结构本身不包含任何指针,我如何将回复评论与个人资料相关联?

const user = request.user
const req = request.params
if (!req) throw 'request params is required'   
if (!req.eventID) throw 'request event params is required'        
const getEventData: ParseEvent = <ParseEvent>await get(Event, req.eventID)

var query = new Parse.Query(EventComment);
    query.equalTo("parent", getEventData);
    query.descending("createdAt");

    const getComments = await query.find();      

    const latestUsers = getComments.map( async parentThread => { 

       let myProfile: Parse.Object = await parentThread.get('profile').fetch(masterKey) // fetch relational profile    
       let getReplies = parentThread.get("replies")

       const returnUser = {
           threadID: parentThread.toJSON().objectId,
           uid: myProfile.get("uid"),
           fullname: myProfile.get("fullname"),
           photos: myProfile.get("photos")[0] || "",   
           comment: parentThread.get("comment"),
           replies: []
       }
        return Promise.resolve( returnUser )
    })
    // Prepare the final timeline data for  the user and merge all data
    const finalUsers = await Promise.all(latestUsers)  

我要实现的最终结果是用真实的实时用户个人资料数据填充replies: []中的returnUser数组,这样,如果他们更改名称或个人资料照片,它将显示而不是仅仅推送数据放入数组并将其存储在其中

0 个答案:

没有答案