从 MongoDB 集合检索组织层次结构的查询

问题描述 投票:0回答:0

我有一个具有分层文档结构的 MongoDB 集合。根层连接到另一个集合,该集合是这些集合的父级。文档架构如下:

{
  "_id": objectId, //(1)
  "_parentNode": objectId,
  "_organisation":objectId // (do the find children job only when this index appears) (2) 
  "name": string
}

查询后我期望的是

[
 {
   "_id": objectId, // organisation's $oid (2)
   "name": string,
   "children": [{objectId},{objectId},...] // list of $oid of (1)
},...
]
mongodb mongoose mongodb-query aggregation-framework
© www.soinside.com 2019 - 2024. All rights reserved.