【问题标题】:not able to query through an array in mongodb aggregation无法通过 mongodb 聚合中的数组进行查询
【发布时间】:2022-12-11 09:37:11
【问题描述】:

这是集合“记录”:

{
    "_id" : "883f6174-fbbb-47f8-b280-7a798e8c0664",
    "history" : [ 
        {
            "_id" : "6bdd2919-9fe5-48b8-a009-5dec0efc10c3",
            "oldStatus" : "-NA-",
            "newStatus" : "IN_PROGRESS",
            "createdAt" : ISODate("2022-07-22T20:58:30.361Z")
        }, 
        {
            "_id" : "eedb3775-93e2-4f0d-afda-0032b7b343dd",
            "oldStatus" : "IN_PROGRESS",
            "newStatus" : "ACCEPTED",
            "createdAt" : ISODate("2022-10-10T16:30:04.781Z")
        }
    ],
    "source" : {
        "$ref" : "Source",
        "$id" : "65268f59-2a92-4414-8a79-c454c8059005"
    },
    "pipelineCreatedAt" : ISODate("2022-07-22T20:58:30.361Z")
}

我试过了

{$addFields: {inProgressDate : {$cond:{if:{$and: [{ $eq: [ "$history.oldStatus", '-NA-' ] },{ $eq: [ "$history.newStatus", 'IN_PROGRESS' ] }]},then:"$history.createdAt",else:null}}}}

期待

我的目标是:

WHERE progress time =  oldStatus : "-NA-" and newStatus : "IN_PROGRESS"
 and accepted time = oldStatus : "IN_PROGRESS" and newStatus : "ACCEPTED"

【问题讨论】:

    标签: arrays mongodb mongodb-query aggregation-framework aggregation


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-16
    • 1970-01-01
    • 2017-09-19
    • 1970-01-01
    • 2019-02-16
    • 2020-07-27
    相关资源
    最近更新 更多