与 MongoDB 相关的帖子?
作为 MongoDB 的新手,我不太确定最佳实践是什么。
目前,帖子分配了一组标签,我想在每个帖子的底部添加一个“相关帖子”部分。在 MongoDB 中实现这一目标的不同/最佳方法是什么?
我最初的猜测是,我会扫描哪些帖子具有任何父帖子的标签,然后我会循环浏览这些帖子并计算它们拥有多少个父帖子的标签。具有最多相同标签的标签将排在第一位。尽管这看起来非常低效。
Being new to MongoDB I'm not really sure what would be the best practice for this.
Currently Posts have a set of tags assigned to them, and I'd like to include at the bottom of each post a "Related Posts" section. What would be the different/best way(s) to accomplish this in MongoDB?
My initial guess is that I would scan for which posts have ANY of the parent post's tags, then I'd cycle through the posts and count how many of the parent post's tags they have. The ones that have the highest amount of same tags would be first. Though this seems incredibly ineffecient.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谢谢大家,我最终将相关文档存储在父文档中。
为了查找相关文档,我找到了所有具有任何父文档标签的文档,然后按它们相互拥有的标签数量进行排序。
逻辑如下:
https://github.com/bevry/docpad/blob/2bcfd152b4b55bab8944c968b8bf093300925319/lib/docpad.coffee#L297
这是架构:
https://github.com/bevry/docpad/blob/2bcfd152b4b55bab8944c968b8bf093300925319/lib/docpad.coffee#L85
Thanks guys, I ended up storing the related documents inside the parent document.
To find related documents, I found all which have ANY of the parent document tags, then sort by how many tags they mutually have.
Here is the logic:
https://github.com/bevry/docpad/blob/2bcfd152b4b55bab8944c968b8bf093300925319/lib/docpad.coffee#L297
Here is the schema:
https://github.com/bevry/docpad/blob/2bcfd152b4b55bab8944c968b8bf093300925319/lib/docpad.coffee#L85