我正在嘗試運(yùn)行一個(gè)$graphLookup類似下面所示的示例:目的是在給定特定記錄($match在此處有注釋)的情況下,通過immediateAncestors屬性檢索其完整的“路徑” 。如您所見,這沒有發(fā)生。我$convert在這里介紹了_idfrom的處理方式,因?yàn)閟tring相信可以與_idfrom immediateAncestors記錄列表(是string)進(jìn)行“匹配” 。因此,我確實(shí)使用不同的數(shù)據(jù)運(yùn)行了另一個(gè)測試(不ObjectId涉及):db.nodos.insert({"id":5,"name":"cinco","children":[{"id":4}]})db.nodos.insert({"id":4,"name":"quatro","ancestors":[{"id":5}],"children":[{"id":3}]})db.nodos.insert({"id":6,"name":"seis","children":[{"id":3}]})db.nodos.insert({"id":1,"name":"um","children":[{"id":2}]})db.nodos.insert({"id":2,"name":"dois","ancestors":[{"id":1}],"children":[{"id":3}]})db.nodos.insert({"id":3,"name":"três","ancestors":[{"id":2},{"id":4},{"id":6}]})db.nodos.insert({"id":7,"name":"sete","children":[{"id":5}]})和查詢:db.nodos.aggregate( [ { $match: { "id": 3 } }, { $graphLookup: { from: "nodos", startWith: "$ancestors.id", connectFromField: "ancestors.id", connectToField: "id", as: "ANCESTORS_FROM_BEGINNING" } }, { $project: { "name": 1, "id": 1, "ANCESTORS_FROM_BEGINNING": "$ANCESTORS_FROM_BEGINNING.id" } }] )...輸出了我期望的結(jié)果(這5條記錄直接或間接與id3 條記錄相關(guān)):{ "_id" : ObjectId("5afe270fb4719112b613f1b4"), "id" : 3.0, "name" : "três", "ANCESTORS_FROM_BEGINNING" : [ 1.0, 4.0, 6.0, 5.0, 2.0 ]}問題是:有沒有一種方法可以實(shí)現(xiàn)我一開始提到的對(duì)象?我正在運(yùn)行Mongo 3.7.9(來自官方Docker)提前致謝!
2 回答

楊魅力
TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超6個(gè)贊
值得寫,因?yàn)槟粫?huì)是最后一個(gè)問它的人。人們現(xiàn)在已經(jīng)問過,誰還不知道這些“轉(zhuǎn)換”功能即將到來。一旦投入生產(chǎn),我希望嘗試它的人數(shù)只會(huì)增加。因此,我想是“感謝您提出的問題”。
- 2 回答
- 0 關(guān)注
- 1382 瀏覽
添加回答
舉報(bào)
0/150
提交
取消