1

値を含むフィールドを除外したい。RESTHeart API で集計を行いました。statusが承認されたか拒否されたかを知りたいです。

データ:

{
    "body": {
        "VERIFIED_MESSAGE": {
            "072ade7d42d871d4fe": {
                "messageId": "bcd1d991-aa63",
                "create": 1486546629585,
                "status": "accept",     //this is what I want to know
                "comment": null
            }
        }
    }
},
{
    "body": {
        "VERIFIED_MESSAGE": {
            "595d0a56cff27": {
                "messageId": "595d0a56c",
                "create": 1486566646197,
                "status": "reject.all",    
                "comment": null
            }
        }
    }
},
{
    "body": {
        "VERIFIED_MESSAGE": {
            "52ffd09bf5bd541602a": {
                "messageId": "1dadce1d",
                "create": 1486568943752,
                "status": "accept",
                "comment": null
            }
        }
    }
}

集計:

{   
    "stages": [
        {"$match": {
            "body.VERIFIED_MESSAGE": {
                "$exists": true, 
                "$ne": null 
            },
        }},
        {"$project": {
            "_id": 0,
            "body.VERIFIED_MESSAGE": 1,
        }},
        {"$group": {
            "_id": null,
            "verified": {
                "$push": {
                    "message": "$body.VERIFIED_MESSAGE"
                }
            }
        }},
        {"$project": {
            "_id": 0,
            "verified": 1,
        }},
    ],
    "type": "pipeline"
}

これにより、次のようになります。

{
    "verified": [{
        "message": {
            "072ade7d42d871d4fe": {
                "messageId": "bcd1d991-aa63",
                "create": 1486546629585,
                "status": "accept",
                "comment": null
            }
        }
    },
    {
        "message": {
            "595d0a56c": {
                "messageId": "595d0a56c",
                "create": 1486566646197,
                "status": "reject.all",
                "comment": null
            }
        }
    },
    {
        "message": {
            "52ffd09bf5bd541602a": {
                "messageId": "1dadce1d",
                "create": 1486568943752,
                "status": "accept",
                "comment": null
            }
        }
    },
]

これを配列に入れましたが、この時点では、新しいエントリごとにオブジェクトの値が変化するため、次に何をすべきかわかりません。これをスキップする方法はありますか?

私が欲しいもの:

{
    "verified": [{
        "message": {
            "messageId": "bcd1d991-aa63",
            "create": 1486546629585,
            "status": "accept",
         }
    },
    {
        "message": {
            "messageId": "595d0a56cff27c1a2fbf3d29e6986688c49d511d",
            "create": 1486566646197,
            "status": "reject.all",
         }
    },
    {
         "message": {
             "messageId": "1dadce1d-a5a6-4d01-b0cf-f34c5e6219eb",
             "create": 1486568943752,
             "status": "accept",
         }
    }]
}

それで、これは可能ですか?

4

1 に答える 1