在从 RDBMS 切换之前需要 MongoDB 专家/开发人员的建议
我们在 SQL2005 中有这些表:
- albums:视频专辑详细信息(类别、标题、标签、日期、作者、 喜欢、观看等
- 标签:专辑标签和标签按字母顺序排序(查找所有带有 特定标签)
- 评级:存储对专辑进行评级的用户的ID(以防止 重复评分)
- 评论:存储专辑上的所有评论
- comment_ ratings:对评论进行评分的用户的ID(以防止重复 rating)
- comment_replies:对带有日期和海报的评论的所有回复 info
- comment_reply_ ratings:对回复进行评分的用户 ID(以防止 重复评级)
可以在 MongoDB 中创建这种类型的结构吗? 以下操作/查询具有相同/更好的性能?
1) 获取最受喜爱的前 10 名相册(标题、缩略图、观看次数、点赞数、 作者&日期)与分页。 如果用户单击“下一步”,则会获取下 10 个最喜欢的专辑和专辑。依此类推
2) 通过分页获取观看次数最多的前 10 名相册。
3) 通过分页获取讨论最多的 10 张专辑。
4) 获取最近创建的相册列表,可分页但最多 100 个 相册
5) 获取给定用户的所有相册(标题、缩略图、视图、喜欢、 作者&日期)
6)获取特定专辑和日期的详细信息仅显示前 10 条评论 寻呼。 接下来将加载接下来的 10 条评论,依此类推。
7) 获取相关专辑列表。关系将通过专辑标签或 专辑标题
8) 按关键字搜索将搜索专辑的标题或标签字段。
9) 当有人点击某个标签时,获取带有该标签的所有专辑列表
10) 当有人点击类别链接时,获取 10 个类别的列表 专辑
11) 获取按评级、日期等排序的评论
12) 文档中新条目的顺序是否可以 受控?
感谢您的阅读。上帝保佑。
We have these tables in SQL2005:
- albums: video album details (category, title, tags, date, author,
likes, views etc - tags: album tags & ordered alphabetically(to find all albums w/ a
particular tag) - ratings: stores the id of the users who rated album(to prevent
duplicate rating) - comments: stores all comments on the album
- comment_ratings: id of the users rated a comment(to prevent duplicate
rating) - comment_replies: all the replies to a comment with date and poster
info - comment_reply_ratings: id of the users who rated a reply(to prevent
duplicate rating)
Can this type of structure be created in MongoDB allowing the
following operations/queries with equal/better performance?
1) Get top 10 most liked albums( title, thumbnail, views, likes,
author & date) with paging.
If user clicks next, get next 10 most liked album & so on
2) Get top 10 most viewed albums with paging.
3) Get top 10 most discussed albums with paging.
4) Get list of recently created albums with paging but up to 100
albums
5) Get all albums by a given user (title, thumbnail, views,likes,
author & date)
6) Get details of a specific album & show just top 10 comments with
paging.
Next will load next 10 comments and so on.
7) Get list of related albums. Relation will be done via album tags or
album title
8) Searching by keywords would search the title or tag field of album.
9) When someone clicks a tag, get the list of all albums with that tag
10)When someone clicks a category link, get the list of 10 category
albums
11)Get comments ordered by ratings, date etc
12)Can the order in which new entries made to the document be
controlled?
Thanks for reading. God bless.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议采用以下结构:
我已将注释移至单独的集合中(而不是将其嵌入相册中),因为目前在 mongodb 中很难通过多于一层的嵌套来更新文档。
现在查询:
1)通过分页获取前 10 个最喜欢的专辑(标题、缩略图、浏览次数、喜欢、作者和日期)。如果用户单击“下一步”,则会获取下 10 个最喜欢的专辑和专辑。依此类推
2) 通过分页获取观看次数最多的前 10 名相册。
3) 通过分页获取讨论最多的 10 张专辑。
4) 获取最近创建的相册列表,可分页,但最多 100 个相册
5) 获取给定用户的所有相册(标题、缩略图、视图、喜欢、作者和日期)
6) 获取特定相册和日期的详细信息通过分页仅显示前 10 条评论。接下来将加载接下来的 10 条评论,依此类推。
7) 获取相关专辑列表。将通过专辑标签或专辑标题进行关联
请说明
8) 按关键字搜索将搜索专辑的标题或标签字段。
注意:可能需要存储标签两次:小写用于搜索,小写用于显示
9)当有人点击标签时,获取带有该标签的所有专辑的列表
注意:使用$在操作员中,您可以通过多个标签名称进行搜索。
10) 当有人点击类别链接时,获取 10 个类别专辑的列表
11) 获取按评分、日期等排序的评论
12) 新条目的顺序对文件进行控制吗?
请澄清
我认为现在您已经看到可以将关系数据库移动到 MongoDB,并且相信您的应用程序使用 mongodb 和以上模式将会非常快;)。
希望这有帮助。
PS:如果sql 2005比我想你使用一些.net语言?
I suggest following structure:
I've moved comments into separate collections (instead of embed it in album) because for now in mongodb hard to update documents with more then one level of nesting.
Now queries:
1) Get top 10 most liked albums( title, thumbnail, views, likes, author & date) with paging. If user clicks next, get next 10 most liked album & so on
2) Get top 10 most viewed albums with paging.
3) Get top 10 most discussed albums with paging.
4) Get list of recently created albums with paging but up to 100 albums
5) Get all albums by a given user (title, thumbnail, views,likes, author & date)
6) Get details of a specific album & show just top 10 comments with paging. Next will load next 10 comments and so on.
7) Get list of related albums. Relation will be done via album tags or album title
Please clarify
8) Searching by keywords would search the title or tag field of album.
Note: Probably need to store tag twice: in lower case for searching, and as is for displaying
9) When someone clicks a tag, get the list of all albums with that tag
Note: Using $in oprator you can search by multiple tag names.
10)When someone clicks a category link, get the list of 10 category albums
11)Get comments ordered by ratings, date etc
12)Can the order in which new entries made to the document be controlled?
Please clarify
I think that now you see that you can move your relational database to MongoDB, and believe your application will be amazing fast with mongodb and above schema ;).
Hope this help.
P.S: If sql 2005 than i suppose you use some .net language?
我看到这类问题在网络上随处可见。您会发现的最常见的答案是为每个作业使用正确的“工具”,因此 Mongo 和标准 RDBMS 都不会比其他数据库更好地适合每个应用程序,但在我看来,您绝对应该投入一些时间学习这个新的“工具”,因为它会让您更好地了解什么更适合您的思维方式和编程风格。
在使用 SQL 数据库多年后,我最近也开始使用 MongoDB,我可以告诉你这是值得的体验。您可以使用 Mongo 做几乎所有事情,绝对是您在清单上描述的所有事情,但要准备在这个过程中做出一些权衡。我不知道你用什么语言。我使用 PHP,我认为 MongoDB 比任何 SQL 数据库都更适合 PHP,从某种意义上说,它以 JSON 格式组织数据,这对于 PHP(数组、类等)树状结构来说更“自然”,允许将整个数组或其一部分转储到数据库,而无需进行大量“映射”并在需要时将其取回。此外,无模式设计可以为您提供更多的灵活性来组织(或不组织:))数据。此外,如果您想开发大型应用程序,MongoDB 将比大多数 SQL DB 更容易扩展。
但对于更“严格”一点的应用程序,其中数据“一致性”和“持久性”更重要,我可能会选择一种老式的 RDMBS 数据库,例如 PostgreSQL。
事实上,如果有必要的话,没有什么可以阻止您在同一个项目中使用这两种工具。
希望这有帮助!
I see these sort of questions popping up all over the web. The most common answer you will find is to use the right "tool" for each job, so neither Mongo nor a standard RDBMS will fit every single application better than the rest of the databases, but to my opinion you should definitely invest some time into learning this new "tool" because it will give you an even better perspective on what fits better your mindset and programming style.
I too have recently started using MongoDB after using SQL databases for years and I can tell you it's worth the experience. You can do just about everything with Mongo, most definitely everything you described on your list, but be prepared to make some trade-offs in the process. I don't know what language you're using. I use PHP and I think MongoDB fits PHP much better then any of the SQL databases do in a sense that it organizes data in JSON format, which is more "natural" to PHP (arrays, classes, etc) tree-like structure, which allows to pretty much dump the whole array or a part of it to the DB without having to do a lot of "mapping" and get it back when you need it. In-addition, shema-less design can give you a little more flexibility on how to organize (or not organize :)) your data. Also, if you want to develop a large application, MongoDB will be a lot easier to scale than most SQL DBs.
But for a little more "strict" applications, where data "consistency" and "durability" is more important, I would probably chose one of the old-fashioned RDMBS databases, such as PostgreSQL.
In fact nothing stops you from using both tools in the same project if you have to.
Hope this helps!