2014-12-04 102 views
0

我試圖決定或找出哪些選項是最佳實踐,當談到流星發佈和MongoDB。流星發佈和MongoDB

我有一個組織,將有超過300個用戶,我的第一個選項只是增加用戶ID陣列組織蒙戈文檔並執行以下操作:

Meteor.publish('organizationsUsers', function() { 
    var organization = Organizations.findOne({_id: this.userId});.fetch(); 
    var usersArray = _.flatten(_.pluck(organization, "users"), true); 
    return Meteor.users.find({_id: {$in: usersArray}}); 
}); 

我的第二個選項,只是增加一個organizationId到每個用戶和執行以下操作:

Meteor.publish('organizationsUsers', function() { 
    var user = Meteor.users.findOne(this.userId); 
    return Meteor.users.find({organizationId: user.organizationId}); 
}); 

隨着第一個選項我有MongoDB的具有長陣列和與所述第二個選項其簡單。

回答

0

好了一些後,一些快速的研究和周圍的一般規則,詢問你的領域更是對100個項目這在我的情況下,將超過300最好是去與第二種方法。

此外,當蒙戈查詢所有屬於與第一個選項蒙戈一個組織中的用戶需要整個陣列,並通過指數看起來每個,只有通過索引第二個選項。

+0

只要確保你有organizationID索引,第二個應該總是會更快。 – 2014-12-04 21:32:24