我建議以下結構:
Album {
Id,
UserId,
Title,
Category,
Tags (list of tag names for fast access and for searching),
Ratings (user ids, use $addToSet),
Likes (user ids, use $addToSet),
ViewsCount, (probably just integer value,)
RatingsCount (use $inc to increment this field once someone vote for album),
CommentsCount (use $inc everytime when someone post comment),
LikesCount (use $inc everytime when someone click 'Like it')
}
Comment {
Id,
AlbumId,
Text,
CreatedDate,
Ratings,
RatingsCount,
Replies { (collection of comment replies)
Text,
CreatedDate,
Ratings,
RatingsCount
}
}
Tag {
Id,
TagName,
AlbumsCount (use $inc: 1 when new album created with this tag
and $inc:-1 - once deleted)
}
我搬到評論到單獨的集合(而不是將它嵌入到專輯),因爲現在在MongoDB中難以更新與嵌套一個以上級文件。
現在查詢:
1)獲得10最喜歡的專輯(標題,縮略圖視圖,喜歡,筆者&日期)與尋呼頂部。如果用戶點擊下一個,下一個獲得10個最喜歡的專輯&等
db.albums.find().skip(0).limit(10).sort({ RatingsCount: -1 });
2)與尋呼獲取10個最觀看的相冊。
db.albums.find().skip(0).limit(10).sort({ ViewsCount: -1 });
3)通過分頁獲得排名前10位的討論最多的專輯。
db.albums.find().skip(0).limit(10).sort({ CommentsCount: -1 });
4)獲得最近創建的相冊列表分頁,但高達100張專輯
db.albums.find().skip(0).limit(100).sort({ CreatedDate: -1 });
5)由給定用戶(標題,縮略圖視圖,喜歡,筆者&日獲取的所有專輯)
db.albums.find({UserId: someUserId})
6)獲取特定相冊&的詳細信息只顯示分頁十大意見。接下來會加載下10條評論等。
album = db.albums.find({_id: someAlbumId});
comments = db.comments.find({AlbumId: someAlbumId }).skip(0)
.limit(10).sort({ RatingsCount: -1 ,CreateDate: -1 });
7)獲取相關相冊列表。關係將通過專輯標籤或專輯名稱進行
請澄清
8)通過關鍵字搜索將搜索專輯的標題或標籤字段。
db.albums.find({ $or : [ { Title : searchKey } , { Tags : searchKey } ] })
注:可能需要存儲標籤兩次:在較低的情況下,用於搜索,並且是用於顯示
9)當用戶點擊一個標籤,獲得與該標籤的所有專輯列表
db.albums.find({Tags : { $in: [tagName1, tagName2]}} ] })
注:oprator使用$您可以通過多個標記名稱進行搜索。
10)當有人點擊一個類別鏈接,獲得的10類專輯
db.albums.find({Category: val }).skip(0).limit(10).sort({ CreatedDate: -1 });
11)獲取收視率排序評論列表,日期等
db.comments.skip(0).limit(10).sort({ RatingsCount: -1 });
12)的順序在哪些新的條目對文件進行控制?
請澄清
我想,現在你看,你可以將你的關係數據庫MongoDB的,相信你的應用程序將是驚人的快與MongoDB的以上模式)。
希望得到這個幫助。
P.S:如果sql 2005比我想你使用一些.net語言?
我已經從不同的rdbms移動了兩個應用程序(第一個約100個sql表,第二個約60個)。這兩個應用程序使用mongodb快速工作。因此,將項目移動到mongodb是一個很好的解決方案(至少在項目之上,因爲對於使用sql仍然至關重要的項目)。 – 2011-03-29 22:19:52
Bugai,我無法告訴你我多麼感激你的回覆。非常感謝你。 – kheya 2011-03-29 23:42:44