2015-10-13 39 views
0

我是MongoDB中的新成員,我試圖做一種「配置文件/評論」模塊。我將這兩個實體保存到兩個不同的集合中,因爲我讀到了有很多嵌套元素的限制(在這種情況下,評論會增長很多)。如何將用戶信息加入評論集? (配置文件/審查案例)

我的模式是:

評論:

{ 
    "_id" : ObjectId("56073ea299f4ebd05df813a8"), 
    "rate" : "0", 
    "owner" : "xub32YLjc4xJa38aM", 
    "to" : "8zqCPbkwYMfajyFQx", 
    "createdAt" : ISODate("2015-09-27T00:56:02.328Z") 
} 

其中:

  • :可以是0或1(壞事,也是好事,簡單)
  • 業主:發表評論的用戶ID
  • :個人資料的ID作出檢討

簡介:

{ 
    "_id" : "8zqCPbkwYMfajyFQx", 
    "CI" : "19", 
    "firstName" : "Alan", 
    "lastName" : "Brito Delgado", 
    "gender" : "m", 
    "bio" : "lorem ipsum haha a bio right here pls", 
    "birthdate" : ISODate("2015-09-26T01:54:46.687Z"), 
    "specialty" : "Medico generalshhh", 
    "worksIn" : "Integramedica", 
    "academicInformation" : "Medicia UC 2010", 
    "avatar_url" : "img/doctor-1.png", 
    "certified" : false 
} 

其中: - CI,專業,WorksIn,AcademicInformation和認證是我使用的字段過濾器配置文件

我的問題是,我想做一個「排名視圖」,人們可以添加過濾器來查看排名基於他們的過濾器,並且,我不知道如何加入關於個人資料和評論的信息。 (排名依據的評價不錯計)

我如何知道通過輪廓分組「好」的評論數的方法,但是,我不知道如何追加「輪廓」信息:

db.reviews.group({ 
    key: {to:1}, 
    cond: {rate:"1"}, 
    reduce: function(curr, result){ 
     result.count++; 
    }, 
    initial: { count: 0 } 
}) 

例用樣品 enter image description here

這可能與我目前的模式?或者我需要嵌入配置文件與評論或追加用戶審查? (用第二種方法,我想我會擁有用戶信息不日期)

PS:我複習情景模式,而非用戶的話,用戶是不同於型材

回答

0

普遍的共識是,如果你不需要被動地發佈,在客戶端進行加入。然而,流星的目的是構建反應式應用。

你看過關係發佈嗎? https://github.com/svasva/meteor-publish-with-relations

你想要的東西,如:

Meteor.publish('rating', function(id) { 
    Meteor.publishWithRelations({ 
     handle: this, 
     collection: ratings, 
     filter: id, 
     mappings: [{ 
     key: '_id', 
     collection: Meteor.profiles 
     }, { 
     reverse: true, 
     key: '_id', 
     collection: Comments, 
     filter: { approved: true }, 
     options: { 
      limit: 10, 
      sort: { createdAt: -1 } 
     }, 
     mappings: [{ 
      key: '_id', 
      collection: Meteor.profiles 
     }] 
     }] 
    }); 
    }); 

參見與反應https://atmosphere.meteor.com/package/reactive-publish

最後,對於流星巨大的資源和電子書值得購買https://www.discovermeteor.com/

PS發佈 - 我以爲你給予標籤的流星答案。如果你想要純mongodb然後上面可能不會幫你

+0

我查看你建議的包,但第一個,是3歲,似乎並沒有在這3年的任何活動,所以,我認爲它將無法正常工作):(在本模塊中沒有必要使用響應式響應)@brianlmerritt – FxckDead

+0

可能不是那麼好:)看看http://meteor.hromnik.com/blog/joins-in-meteorjs-and-mongodb,也在github上https://github.com/Elfoslav/meteor-join-collections – brianlmerritt

+0

ps - 對不起,我現在停留了一段時間,但可能設置了一個meteorpad?這就像一個jsfiddle或codepen http://meteorpad.com/ – brianlmerritt