Mongodb:在具有多个关系的单个集合中应用组

时间:2016-12-27 13:04:41

标签: mongodb mongodb-query loopbackjs database

示例:集合名称为Account,其中包含类别,upvotes和downvotes。 Upvotes和downvotes基本上是类别的馈送。 Collection的结构如下:

{
    "id": "585a2f2735cc577c178bda2b",
    "category_ids": [
        "5857e65c950cfd241818abc3",
        "5857e92f950cfd241818abd0",
        "5857e957950cfd241818abd2",
        "5857f03f950cfd241818abd5"
    ],
    "upVotes": [
        {
            "id": "585a6ccc055f93cbb10bd179",
            "name": "career feed",
            "category_ids": [
                "5857e65c950cfd241818abc3"
            ]
        },
        {
            "id": "5860bc714b7b3a400ef96d2a",
            "name": "Treasurers and Controllers",
            "category_ids": [
                "5857e957950cfd241818abd2"
            ]
         }
    ],
    "downVotes": [
        {
            "id": "585a8fbb416ecf300c6ea969",
            "name": "testinggggg",
            "category_ids": [
                "5857f03f950cfd241818abd5",
                "5857f07c950cfd241818abd6"
            ]
        },
        {
            "id": "585a8406354db7d811f9a405",
            "name": "feeds5",
            "category_ids": [
                "5857e957950cfd241818abd2",
                "5857f07c950cfd241818abd6"
            ]
        }
    ]
}

我想根据用户类别显示downvotes和upvotes。 [在Mongo DB上工作]

输出:

"Category": [{
    "id": "585a6ccc055f93cbb10bd179",
    "upvotes": [{
        "id": "",
        "name": ""
    }, {
        "id": "",
        "name": ""
    }],
    "downvotes": [{
        "id": "",
        "name": ""
    }, {
        "id": "",
        "name": ""
    }]
}]

0 个答案:

没有答案