如何查找由id标识的帖子中涉及的所有不同用户?

时间:2017-10-05 18:35:22

标签: mongodb mongodb-query

以下是帖子集合中的2个帖子对象。我想通过回答或投票或问题本身找到所有涉及的用户。 posttype确定它是一个问题还是一个答案:

对于Q

posttype = 1

发布类型= 2表示ans

/* 7 */
{
    "_id" : 121.0,
    "posttypeID" : 1.0,
    "tags" : [ 
        "science", 
        "technology", 
        "math"
    ],
    "viewCount" : 10.0,
    "votes" : [ 
        {
            "_id" : 1201.0,
            "user" : 124.0
        }, 
        {
            "_id" : 12011.0,
            "user" : 1241.0
        }, 
        {
            "_id" : 12012.0,
            "user" : 1241.0
        }
    ],
    "answers" : [ 
        {
            "_id" : 121.0,
            "posttypeID" : 2.0,
            "tags" : [ 
                "science", 
                "technology", 
                "math"
            ],
            "viewCount" : 10.0,
            "votes" : [ 
                {
                    "_id" : 1201.0,
                    "user" : 124.0
                }, 
                {
                    "_id" : 1201.0,
                    "user" : 124.0
                }, 
                {
                    "_id" : 1201.0,
                    "user" : 124.0
                }
            ]
        }, 
        {
            "_id" : 122.0,
            "posttypeID" : 2.0,
            "tags" : [ 
                "science", 
                "technology", 
                "math"
            ],
            "viewCount" : 10.0,
            "votes" : [ 
                {
                    "_id" : 1201.0,
                    "user" : 124.0
                }, 
                {
                    "_id" : 1201.0,
                    "user" : 124.0
                }, 
                {
                    "_id" : 1201.0,
                    "user" : 124.0
                }
            ]
        }, 
        {
            "_id" : 121.0,
            "posttypeID" : 2.0,
            "tags" : [ 
                "science", 
                "technology", 
                "math"
            ],
            "viewCount" : 10.0,
            "votes" : [ 
                {
                    "_id" : 1201.0,
                    "user" : 124.0
                }, 
                {
                    "_id" : 1201.0,
                    "user" : 124.0
                }, 
                {
                    "_id" : 1201.0,
                    "user" : 124.0
                }
            ]
        }
    ]
}

/* 8 */
{
    "_id" : 11.0,
    "posttypeID" : 1.0,
    "tags" : [ 
        "social", 
        "technology", 
        "arts"
    ],
    "viewCount" : 20.0,
    "votes" : [ 
        {
            "_id" : 1.0,
            "user" : 122.0
        }, 
        {
            "_id" : 2.0,
            "user" : 123.0
        }, 
        {
            "_id" : 12012.0,
            "user" : 1241.0
        }
    ],
    "answers" : [ 
        {
            "_id" : 12.0,
            "posttypeID" : 2.0,
            "tags" : [ 
                "social", 
                "arts", 
                "math"
            ],
            "viewCount" : 10.0,
            "votes" : [ 
                {
                    "_id" : 3.0,
                    "user" : 124.0
                }, 
                {
                    "_id" : 14.0,
                    "user" : 124.0
                }, 
                {
                    "_id" : 15.0,
                    "user" : 123.0
                }
            ]
        }, 
        {
            "_id" : 50.0,
            "posttypeID" : 2.0,
            "tags" : [ 
                "science", 
                "usa", 
                "arts"
            ],
            "viewCount" : 50.0,
            "votes" : [ 
                {
                    "_id" : 1202.0,
                    "user" : 120.0
                }, 
                {
                    "_id" : 1203.0,
                    "user" : 121.0
                }, 
                {
                    "_id" : 1204.0,
                    "user" : 124.0
                }
            ]
        }, 
        {
            "_id" : 60.0,
            "posttypeID" : 2.0,
            "tags" : [ 
                "science", 
                "technology", 
                "math"
            ],
            "viewCount" : 5.0,
            "votes" : [ 
                {
                    "_id" : 1205.0,
                    "user" : 121.0
                }, 
                {
                    "_id" : 1206.0,
                    "user" : 123.0
                }, 
                {
                    "_id" : 1207.0,
                    "user" : 122.0
                }
            ]
        }
    ]
}

/* 9 */
{
    "_id" : 115.0,
    "posttypeID" : 1.0,
    "tags" : [ 
        "social", 
        "technology", 
        "arts"
    ],
    "viewCount" : 5.0,
    "votes" : [ 
        {
            "_id" : 1208.0,
            "user" : 122.0
        }, 
        {
            "_id" : 1209.0,
            "user" : 120.0
        }
    ],
    "answers" : [ 
        {
            "_id" : 21.0,
            "posttypeID" : 2.0,
            "tags" : [ 
                "social", 
                "arts", 
                "usa"
            ],
            "viewCount" : 2.0,
            "votes" : {}
        }, 
        {
            "_id" : 110.0,
            "posttypeID" : 2.0,
            "tags" : [ 
                "wiki", 
                "usa", 
                "arts"
            ],
            "viewCount" : 0.0,
            "votes" : [ 
                {
                    "_id" : 1210.0,
                    "user" : 124.0
                }
            ]
        }, 
        {
            "_id" : 100.0,
            "posttypeID" : 2.0,
            "tags" : [ 
                "usa", 
                "wiki"
            ],
            "viewCount" : 5.0,
            "votes" : [ 
                {
                    "_id" : 1211.0,
                    "user" : 125.0
                }
            ]
        }
    ]
}

以下是用户集合

/ * 1 * / {     " _id" :124.0,     " CreationDate" :" 2013-05-08T18:26:05.680",     " DisplayName的" :" hairboat",     "年龄" :23.0,     "给予好评" :1.0,     " DownVote" :0.0 }

/ * 2 * / {     " _id" :1241.0,     " CreationDate" :" 2013-05-08T18:26:05.680",     " DisplayName的" :" jamie",     "年龄" :40.0,     "给予好评" :10.0,     " DownVote" :5.0 }

/ * 3 * / {     " _id" :120.0,     " CreationDate" :" 2013-05-08T18:26:05.680",     " DisplayName的" :" jamie",     "年龄" :40.0,     "给予好评" :10.0,     " DownVote" :5.0 }

/ * 4 * / {     " _id" :121.0,     " CreationDate" :" 2013-05-08T19:01:56.490",     " DisplayName的" :"凯西",     "年龄" :30.0,     "给予好评" :120.0,     " DownVote" :10.0 }

/ * 5 * / {     " _id" :122.0,     " CreationDate" :" 2013-05-08T19:03:27.963",     " DisplayName的" :" user15",     "年龄" :30.0,     "给予好评" :1.0,     " DownVote" :0.0 }

/ * 6 * / {     " _id" :123.0,     " CreationDate" :" 2013-05-08T19:03:27.963",     " DisplayName的" :" user15",     "年龄" :30.0,     "给予好评" :1.0,     " DownVote" :0.0 }

/ * 7 * / {     " _id" :12.0,     " CreationDate" :" 2013-05-08T19:03:27.963",     " DisplayName的" :" user15",     "年龄" :30.0,     "给予好评" :1.0,     " DownVote" :0.0 }

0 个答案:

没有答案