mongodb - 未填充 2 级对象中的 mongoose ref
问题描述
我有两个模式Workflow
,CloudFunction
其中工作流模式包含节点数组,它是对象数组。每个对象都有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 questions 中提到的多种方法,但似乎对我的模型没有任何作用。任何线索模型或下面提到的查询有什么问题:
model.find({"name":req.query.workflowName})
.populate({path:'nodes.nodeConfig.cloudFunction',model:'CloudFunction'})
此查询返回数据但不填充 CloudFunction Model 的project
andfunctionName
字段。
在 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,
}
解决方案
推荐阅读
- ruby-on-rails - 设计通过电子邮件和子域查找密码重置
- sql - 尝试在 SQL 中使用 COUNT 进行 CONCAT
- vue.js - 防止按钮被聚焦(VueJS,Buefy)
- python-3.x - 当我尝试使用 pip 安装 autopep8 时,为什么会出现此错误?
- batch-file - 从命令行执行可视化脚本
- tsql - 如何以正确的月份顺序显示最后滚动的 12 个月
- java - java中如何传值?
- php - WooCommerce 类别中的附加图像字段
- postgresql - jsonb访问数组元素
- selenium - Jmeter - 从外部文件发送正文数据时响应正文出错