You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Process Id获取流程详情的MongoDB查询需求及样本数据

Fetch Process Details by Process Instance ID in MongoDB

Hey there, based on your sample data, here's how you can query MongoDB to get all process details using a specific processInstanceId:

Basic Query

First, assuming your collection is named something like process_activities (replace this with your actual collection name), the core query targets the nested data.processInstanceId field:

db.process_activities.find({
  "data.processInstanceId": "33" // Swap this with your target Process Instance ID
})

Using your sample data, this will pull the document with _id: ObjectId("5ac70a54306dfa497877de85") since its processInstanceId matches "33".

Filter by Document Type (Optional)

If you only want documents of a specific type (like activity-full from your sample), add an extra condition to narrow results:

db.process_activities.find({
  "type": "activity-full",
  "data.processInstanceId": "33"
})

Project Specific Fields (Optional)

If you don’t need the entire document and want to focus only on the process details in the data field, use projection to trim the output:

db.process_activities.find(
  { "data.processInstanceId": "33" },
  { "_id": 0, "data": 1 } // Exclude the _id field, include only the data object
)

This will return a streamlined result like:

{
  "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"
  }
}

Sort Results by Timestamp (Optional)

If you want to order activities chronologically, add a sort clause to the query:

db.process_activities.find({ "data.processInstanceId": "33" })
  .sort({ "data.__timeStamp": 1 }) // Use 1 for ascending order, -1 for descending

That should cover all common scenarios for fetching process details by instance ID!

内容的提问来源于stack exchange,提问作者arjunsekar1991

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:26:56