Reg: Data is not providing correct number in mongo aggregate function

别说谁变了你拦得住时间么 提交于 2020-12-23 18:31:05

问题


Using below query to get the output:

db.action.aggregate([{
        $match: {
            "$and": [{
                "timeStamp": {
                    "$gte": ISODate("2020-12-13T00:00:00.000-0400"),
                    "$lt": ISODate("2020-12-15T23:59:59.000-0400")
                }
            }, {
                "functionStatus": "FMO_UVERSE_DTV"
            }]
        }
    },
    {
        $group: {
            _id: {
                Dates: {
                    $dateToString: {
                        format: "%Y-%m-%d",
                        date: "$timeStamp"
                    }
                },
                FS: "$functionStatus"
            },
            JOBCOUNT: {
                $addToSet: "$jobId"
            }
        }
    },
    {
        $project: {
            "_id": NumberInt(0),
            "Dates": "$_id.Dates",
            "FS": "$_id.FS",
            "Total_JOB_FMO_UVERSE_DTV": {
                $size: "$JOBCOUNT"
            }
        }
    },
    {
        $sort: {
            Dates: 1
        }
    }
])

When checking with 13 to 15th dates in above query below is the output.

/* 1 */
{
    "Dates" : "2020-12-13",
    "FS" : "FMO_UVERSE_DTV",
    "Total_JOB_FMO_UVERSE_DTV" : 14
}

/* 2 */
{
    "Dates" : "2020-12-14",
    "FS" : "FMO_UVERSE_DTV",
    "Total_JOB_FMO_UVERSE_DTV" : 973
}

/* 3 */
{
    "Dates" : "2020-12-15",
    "FS" : "FMO_UVERSE_DTV",
    "Total_JOB_FMO_UVERSE_DTV" : 43
}

When checking with dates: 11th to 15th below is output coming where count for 13th Dec is showing 46, what needs to implement to get correct count.

====================================================================

/* 1 */
{
    "Dates" : "2020-12-11",
    "FS" : "FMO_UVERSE_DTV",
    "Total_JOB_FMO_UVERSE_DTV" : 1198
}

/* 2 */
{
    "Dates" : "2020-12-12",
    "FS" : "FMO_UVERSE_DTV",
    "Total_JOB_FMO_UVERSE_DTV" : 812
}

/* 3 */
{
    "Dates" : "2020-12-13",
    "FS" : "FMO_UVERSE_DTV",
    "Total_JOB_FMO_UVERSE_DTV" : 46
}

/* 4 */
{
    "Dates" : "2020-12-14",
    "FS" : "FMO_UVERSE_DTV",
    "Total_JOB_FMO_UVERSE_DTV" : 973
}

/* 5 */
{
    "Dates" : "2020-12-15",
    "FS" : "FMO_UVERSE_DTV",
    "Total_JOB_FMO_UVERSE_DTV" : 43
}

来源:https://stackoverflow.com/questions/65303137/reg-data-is-not-providing-correct-number-in-mongo-aggregate-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!