Mongo数据库查询根据进程ID获取进程详细信息

时间:2018-04-06 12:44:10

标签: mongodb aggregation-framework

我有一个mongo数据样本,如下所示

{
    "_id" : ObjectId("5ac70a54306dfa497877de85"),
    "type" : "activity-full",
    "data" : {
        "processDefinitionId" : "myProcess:1:4",
        "processInstanceId" : "33",
        "executionId" : "34",
        "activityId" : "start",
        "__timeStamp" : "2018-04-06T05:49:08.416Z",
        "activityName" : "start event",
        "tenantId" : "",
        "startTime" : "2018-04-06T05:49:08.416Z",
        "endTime" : "2018-04-06T05:49:08.416Z",
        "activityType" : "startEvent"
    }
}

,
{
    "_id" : ObjectId("5ac70a54306dfa497877de86"),
    "type" : "task-created",
    "data" : {
        "taskDefinitionKey" : "usertask",
        "processDefinitionId" : "myProcess:1:4",
        "processInstanceId" : "33",
        "executionId" : "34",
        "activityId" : "usertask",
        "__timeStamp" : "2018-04-06T05:49:08.416Z",
        "name" : "User Task",
        "tenantId" : "",
        "startTime" : "2018-04-06T05:49:08.416Z",
        "id" : "35",
        "priority" : "50"
    }
},

{
    "_id" : ObjectId("5ac70a54306dfa497877de87"),
    "type" : "task-assignee-changed",
    "data" : {
        "executionId" : "34",
        "activityId" : "usertask",
        "__timeStamp" : "2018-04-06T05:49:08.416Z",
        "createTime" : "2018-04-06T05:49:08.416Z",
        "activityAssigneeHandled" : "true",
        "assignee" : "any",
        "id" : "35",
        "processInstanceId" : "33"
    }
},

{
    "_id" : ObjectId("5ac70a54306dfa497877de88"),
    "type" : "task-property-changed",
    "data" : {
        "taskDefinitionKey" : "usertask",
        "processDefinitionId" : "myProcess:1:4",
        "__timeStamp" : "2018-04-06T05:49:08.416Z",
        "name" : "User Task",
        "id" : "35",
        "assignee" : "any",
        "priority" : "50",
        "processInstanceId" : "33"
    }
},

{
    "_id" : ObjectId("5ac70a54306dfa497877de89"),
    "type" : "identitylink-created",
    "data" : {
        "processInstanceId" : "33",
        "__timeStamp" : "2018-04-06T05:49:08.416Z",
        "identityLinkType" : "participant",
        "id" : "36",
        "userId" : "any"
    }
},

{
    "_id" : ObjectId("5ac70a6a306dfa497877de8a"),
    "type" : "activity-end",
    "data" : {
        "processDefinitionId" : "myProcess:1:4",
        "processInstanceId" : "29",
        "executionId" : "30",
        "activityId" : "usertask",
        "__timeStamp" : "2018-04-06T05:49:30.693Z",
        "activityName" : "User Task",
        "tenantId" : "",
        "endTime" : "2018-04-06T05:49:30.693Z",
        "activityType" : "userTask"
    }
},

{
    "_id" : ObjectId("5ac70a6a306dfa497877de8b"),
    "type" : "activity-full",
    "data" : {
        "processDefinitionId" : "myProcess:1:4",
        "processInstanceId" : "29",
        "executionId" : "30",
        "activityId" : "end",
        "__timeStamp" : "2018-04-06T05:49:30.697Z",
        "activityName" : "End event",
        "tenantId" : "",
        "startTime" : "2018-04-06T05:49:30.693Z",
        "endTime" : "2018-04-06T05:49:30.697Z",
        "activityType" : "endEvent"
    }
},

{
    "_id" : ObjectId("5ac70a6a306dfa497877de8c"),
    "type" : "task-ended",
    "data" : {
        "processDefinitionId" : "myProcess:1:4",
        "processInstanceId" : "29",
        "priority" : "50",
        "taskDefinitionKey" : "usertask",
        "executionId" : "30",
        "activityId" : "usertask",
        "__timeStamp" : "2018-04-06T05:49:30.690Z",
        "name" : "User Task",
        "tenantId" : "",
        "startTime" : "2018-04-06T05:49:30.690Z",
        "id" : "31",
        "assignee" : "any",
        "endTime" : "2018-04-06T05:49:30.690Z"
    }
},

{
    "_id" : ObjectId("5ac70a6a306dfa497877de8d"),
    "type" : "process-instance-end",
    "data" : {
        "processInstanceId" : "29",
        "processDefinitionId" : "myProcess:1:4",
        "activityId" : "end",
        "startActivityId" : "start",
        "__timeStamp" : "2018-04-06T05:49:30.744Z",
        "tenantId" : "",
        "processDefinitionName" : "My process",
        "startTime" : "2018-04-06T05:49:06.429Z",
        "id" : "29",
        "endTime" : "2018-04-06T05:49:30.744Z",
        "processDefinitionVersion" : "1",
        "processDefinitionKey" : "myProcess"
    }
},

{
    "_id" : ObjectId("5ac70a6a306dfa497877de8e"),
    "type" : "activity-end",
    "data" : {
        "processDefinitionId" : "myProcess:1:4",
        "processInstanceId" : "33",
        "executionId" : "34",
        "activityId" : "usertask",
        "__timeStamp" : "2018-04-06T05:49:30.822Z",
        "activityName" : "User Task",
        "tenantId" : "",
        "endTime" : "2018-04-06T05:49:30.822Z",
        "activityType" : "userTask"
    }
},

{
    "_id" : ObjectId("5ac70a6a306dfa497877de8f"),
    "type" : "activity-full",
    "data" : {
        "processDefinitionId" : "myProcess:1:4",
        "processInstanceId" : "33",
        "executionId" : "34",
        "activityId" : "end",
        "__timeStamp" : "2018-04-06T05:49:30.827Z",
        "activityName" : "End event",
        "tenantId" : "",
        "startTime" : "2018-04-06T05:49:30.823Z",
        "endTime" : "2018-04-06T05:49:30.827Z",
        "activityType" : "endEvent"
    }
},

{
    "_id" : ObjectId("5ac70a6a306dfa497877de90"),
    "type" : "task-ended",
    "data" : {
        "processDefinitionId" : "myProcess:1:4",
        "processInstanceId" : "33",
        "priority" : "50",
        "taskDefinitionKey" : "usertask",
        "executionId" : "34",
        "activityId" : "usertask",
        "__timeStamp" : "2018-04-06T05:49:30.815Z",
        "name" : "User Task",
        "tenantId" : "",
        "startTime" : "2018-04-06T05:49:30.815Z",
        "id" : "35",
        "assignee" : "any",
        "endTime" : "2018-04-06T05:49:30.815Z"
    }
},

{
    "_id" : ObjectId("5ac70a6a306dfa497877de91"),
    "type" : "process-instance-end",
    "data" : {
        "processInstanceId" : "33",
        "processDefinitionId" : "myProcess:1:4",
        "activityId" : "end",
        "startActivityId" : "start",
        "__timeStamp" : "2018-04-06T05:49:30.881Z",
        "tenantId" : "",
        "processDefinitionName" : "My process",
        "startTime" : "2018-04-06T05:49:08.414Z",
        "id" : "33",
        "endTime" : "2018-04-06T05:49:30.881Z",
        "processDefinitionVersion" : "1",
        "processDefinitionKey" : "myProcess"
    }
},

{
    "_id" : ObjectId("5ac7444e306dfa497877de92"),
    "type" : "process-instance-start",
    "data" : {
        "processInstanceId" : "2505",
        "processDefinitionId" : "myProcess:2:2504",
        "startActivityId" : "start",
        "__timeStamp" : "2018-04-06T09:56:29.836Z",
        "tenantId" : "",
        "processDefinitionName" : "My process",
        "startTime" : "2018-04-06T09:56:29.830Z",
        "id" : "2505",
        "processDefinitionVersion" : "2",
        "processDefinitionKey" : "myProcess"
    }
},

{
    "_id" : ObjectId("5ac7444e306dfa497877de93"),
    "type" : "activity-start",
    "data" : {
        "processDefinitionId" : "myProcess:2:2504",
        "processInstanceId" : "2505",
        "executionId" : "2506",
        "activityId" : "usertask",
        "__timeStamp" : "2018-04-06T09:56:29.859Z",
        "activityName" : "User Task",
        "tenantId" : "",
        "startTime" : "2018-04-06T09:56:29.859Z",
        "assignee" : "any",
        "activityType" : "userTask"
    }
},

{
    "_id" : ObjectId("5ac7444e306dfa497877de94"),
    "type" : "activity-full",
    "data" : {
        "processDefinitionId" : "myProcess:2:2504",
        "processInstanceId" : "2505",
        "executionId" : "2506",
        "activityId" : "start",
        "__timeStamp" : "2018-04-06T09:56:29.857Z",
        "activityName" : "start event",
        "tenantId" : "",
        "startTime" : "2018-04-06T09:56:29.854Z",
        "endTime" : "2018-04-06T09:56:29.857Z",
        "activityType" : "startEvent"
    }
},

{
    "_id" : ObjectId("5ac7444e306dfa497877de95"),
    "type" : "task-created",
    "data" : {
        "taskDefinitionKey" : "usertask",
        "processDefinitionId" : "myProcess:2:2504",
        "processInstanceId" : "2505",
        "executionId" : "2506",
        "activityId" : "usertask",
        "__timeStamp" : "2018-04-06T09:56:29.883Z",
        "name" : "User Task",
        "tenantId" : "",
        "startTime" : "2018-04-06T09:56:29.883Z",
        "id" : "2507",
        "priority" : "50"
    }
},

{
    "_id" : ObjectId("5ac7444e306dfa497877de96"),
    "type" : "task-assignee-changed",
    "data" : {
        "executionId" : "2506",
        "activityId" : "usertask",
        "__timeStamp" : "2018-04-06T09:56:29.885Z",
        "createTime" : "2018-04-06T09:56:29.885Z",
        "activityAssigneeHandled" : "true",
        "assignee" : "any",
        "id" : "2507",
        "processInstanceId" : "2505"
    }
},

{
    "_id" : ObjectId("5ac7444e306dfa497877de97"),
    "type" : "task-property-changed",
    "data" : {
        "taskDefinitionKey" : "usertask",
        "processDefinitionId" : "myProcess:2:2504",
        "__timeStamp" : "2018-04-06T09:56:29.885Z",
        "name" : "User Task",
        "id" : "2507",
        "assignee" : "any",
        "priority" : "50",
        "processInstanceId" : "2505"
    }
},

{
    "_id" : ObjectId("5ac7444e306dfa497877de98"),
    "type" : "identitylink-created",
    "data" : {
        "processInstanceId" : "2505",
        "__timeStamp" : "2018-04-06T09:56:29.911Z",
        "identityLinkType" : "participant",
        "id" : "2508",
        "userId" : "any"
    }
}

我想要做的是基本上找到与processInstanceId相关的所有数据[流程实例ID和输出的输入数组具有包含流程实例ID的记录]。 processInstanceId id派生自process-instance-end类型。我想在一个mongo查询中执行此操作。 Mongo数据库专家可以帮助我。

1 个答案:

答案 0 :(得分:0)

听起来你想要做的只是为一个processInstanceIds数组执行FIND,而不是逐个查找它们。如果是这样的话,请点击这里:

db.getCollection('CollectionName').find({"data.processInstanceId": {$in: ["33","2505"]}})

这将返回该数组中包含processInstanceId的所有文档[" 33"," 2505"]。