我從兩個單獨的mongodb模式向下面的對象填充數據: 他們是用戶和文章。我如何篩選/排序,以便我可以通過user._id找到骨幹文章? 這是針對單個頁面的博客類型網站,其中每個用戶都有自己的文章。如何在主幹中篩選此JSON?
我在看_.filter和_.where函數在下劃線中,但我對此仍然陌生。任何幫助表示讚賞。謝謝。
這裏是我的什麼即時試圖建立服務器上的一個例子(與嵌入式架構完成): http://kevg.co:3700/demo1 和骨幹模型/視圖/收集代碼是在這裏: http://kevg.co:3700/javascripts/demoj17.js
//Individual Model
{
"user": {
"username": "ho",
"email": "[email protected]",
"_id": "51be709a148846ec25000007"
},
"name": "money",
"articlebody": "",
"_id": "51c1033283376a5808000002",
"__v": 0,
"createdAt": "2013-06-19T01:02:42.424Z"
},
//Rest of data
{
"user": {
"username": "kev",
"email": "[email protected]",
"_id": "51be6fe9148846ec25000001"
},
"name": "bob",
"articlebody": "",
"_id": "51c89ab47596ef1018000001",
"__v": 0,
"createdAt": "2013-06-24T19:15:00.835Z"
},
{
"user": {
"username": "kev",
"email": "[email protected]",
"_id": "51be6fe9148846ec25000001"
},
"name": "sasa",
"articlebody": "sajdja",
"_id": "51c8a3bf341eb4141f000001",
"__v": 0,
"createdAt": "2013-06-24T19:53:35.233Z"
}
如果您可以發佈現有Backbone模型和集合定義的示例,這可能會有所幫助。 – damienc88