在 mongodb 中存储/使用文档管理系统的标签
所以我正在开发一个宠物项目,在其中存储各种文本文件。我已经设置我的应用程序将标签保存为我的集合之一中的字符串,因此示例如下:
标签:“Linux Apache WSGI”
存储它们并搜索它们工作得很好,但当我想做类似的事情时,我的问题就出现了一个标签云,统计所有不同的标签,或者制作一个基于标签的动态选择系统,将它们分解并使用的最佳方法是什么?或者我应该以其他方式存储它们?
从逻辑上讲,我可以扫描每条记录并获取所有标签,根据空间打破它们,然后以某种方式缓存结果。也许这是正确的答案,但我想询问社区的智慧。
我正在使用 pymongo 与我的数据库交互。
So I am working on a pet project where I'm storing various text files. I have setup my app to save the tags as a string in one of my collections so an example would be:
tags: "Linux Apache WSGI"
Storing them and searching for them work just fine but my question comes when I want to do something like a tag cloud, count all the various tags, or make a dynamic selection system based on tags, what is the best way to break them up to work with? Or should I be storing them some other way?
Logically I could scan through every record and get all the tags, break them based on space, then cache the result somehow. Maybe that's the right answer but I wanted to ask the community wisdom.
I'm using pymongo to interact with my database.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
存储标签的标准方法是将它们存储为数组。在你的情况下,数据库看起来像:
这就是 Map/Reduce 的设计目的。这有效地“扫描每条记录”。 Map/Reduce 的输出是您可以查询的另一个集合。
然而,还有另一种方法可以做到这一点,那就是保留“计数器”并更新它们。因此,当您保存新文档时,您还会增加与该文档相关的所有标签。
The standard way to store tags is to store them as an array. In your case, the DB would look something like:
This is what Map/Reduce is designed for. This effectively "scans every record". The output of a Map/Reduce is another collection that you can query.
However, there's also another way to do this and that's to keep "counters" and update them. So when you save a new document you also increment all of the tags related to that document.