2016-09-06 64 views
0

我有3層存儲在mongoDB中的嵌套對象。 第一層顯示它應該的名字,第二層也是如此。 但是當它進入第三層時,它顯示文本:「wrappedPointCut」 這是爲什麼?以及wrapedPointCut是什麼意思?爲什麼我會使用wrappedPointCut而不是數據?

我有一個車把測試這樣的代碼:

{{#each tierOne}} 
<h2>{{ this.tierOneName }}</h2> 
    {{#each tierTwo}} 
    <h2>{{ this.tierTwoName }}</h2>   
    {{#each tierThree}} 
    <h2>{{ this.tierThreeName }}</h2> 
    {{/each}} 
    {{/each}} 
{{/each}} 
</div> 

當通過JS嵌套對象進行迭代,我得到在控制檯中正確的輸出。另外,如果我添加4個對象到第三層,我會得到4個標題:「wrapedPointCut」。這意味着它知道這裏有數據。

這是MongoDB的結構: 這是第3層:

var TierThree = new mongoose.Schema({ 
    tierThreeName : { 
     type: String 
    } 
}); 

這是第2層:

var TierTwo = new mongoose.Schema({ 
    tierTwoName : { 
     type: String 
    }, 
    tierThree : [TierThree] 
}); 

這是第1層:

var TierOne = mongoose.Schema({ 
    tierOneName : { 
     type: String, 
     index:true 
    }, 
    tierTwo: [TierTwo] 

}); 

以下是將第三層導出到monngoDB的功能:

module.exports.createTierThree = function(newTierThree, tierOne, tierTwoName , callback){ 
for (var i = 0; i < tierOne.tierTwo.length; i++) { 
     if(tierOne.tierTwo[i].tierTwoName == tierTwoName){     
      tierOne.tierTwo[i].tierThree.push(newTierThree); 
      tierOne.tierTwo[i].save(function (err) { 
       if (!err) console.log('Success!'); 
      }); 
     } 
    } 
}; 
+0

如果您顯示以json格式導出的數據的一個示例,這將有所幫助 –

+0

我做了一個編輯,我希望這有助於清除它。我非常感謝一些幫助,因爲我在這裏迷路了。我認爲我的問題可能會像我在第一部分中所顯示的那樣迭代。 – fredriwa

+0

這不是我所期望的:您能否提供一個與您呼叫車把模板的數據樣本。 –

回答

0

問題似乎是我在添加到數據庫時做錯了什麼。如果我使用shell命令添加到數據庫,一切都很好。所以現在的問題是將mongoDB shell命令轉換爲JS。

相關問題