第二级对象中的猫鼬参考未填充

时间:2021-06-08 17:16:28

标签: mongodb mongoose

我有两个架构 WorkflowCloudFunction,其中工作流架构包含节点数组,它是对象数组。每个对象都有 nodeConfig 对象,其中包含 cloudFunction 字段。 cloudFunction 字段是对 CloudFunction 模型的引用。

这是一个架构:

工作流程:

 {
  name: {
    type: String,
    required: [true, "Function name is required"]
  },
  startNode:{
    type:{}
  },
  nodes: {
    type: [{ 
        nodeType:{type:String},
        nodeId:{type:String},
        nodeName:{type:String},
        nodeConfig:{
          
          type:{
            headerTemplate:{type:[], default:[]},
            cloudFunction:{type:Schema.Types.ObjectId, ref:"CloudFunction"}, 
        },
      },
      
      }]
  },

 }

云函数

{
  functionName: {
    type: String,
    required: [true, "Function name is required"]
  },
  project:{
    type:String,
  }
}

我尝试了 SO 问题中提到的多种方法,但似乎没有任何方法适用于我的模型。任何线索模型或下面提到的查询有什么问题:

model.find({"name":req.query.workflowName})
.populate({path:'nodes.nodeConfig.cloudFunction',model:'CloudFunction'})

此查询返回数据但不填充 CloudFunction 模型的 projectfunctionName 字段。

在 mongoDB 中集合名称显示为:

  • 工作流程
  • 云函数

mongodb 中的数据如下所示:

工作流数据

{

"_id" : ObjectId("60a3fba5dc21904274910be7"),
"name" : "dfs",
"nodes" : [
    {
        "nodeConfig" : {
            "headerTemplate" : [ ],
            "cloudFunction" : ObjectId("60b22fb40523ea419c1253af"),
        },
        "_id" : ObjectId("60bf7d1e09497a499862ce78"),
        "nodeType" : "TEST",
        "nodeId" : "1622471592835",
        "nodeName" : "test"
    }
],
"__v" : 0,
}

云函数数据

{
"_id" : ObjectId("60b22fb40523ea419c1253af"),
"functionName" : "test",
"project":"TEST_PROJ"
"__v" : 0,

}

0 个答案:

没有答案