用于存储用户位置历史记录的 MongoDB 架构
我想使用 MongoDB 来存储我的用户位置历史记录(当然要征得他们的同意)。我看到以下三个选项:
- 为所有用户创建一个位置集合。每个文档都有一个 userId 字段和一个时间字段,这两个字段都将被索引。该集合中的行数可能会增长到超过 1 亿行。
- 创建一个包含其位置作为嵌入数组的用户的集合。这使得搜索位置变得更加困难,因为 MongoDB 显然不支持返回嵌入文档的查询。
- 为每个用户创建一个包含他/她的位置历史记录的集合。我知道一个 MongoDB 实例的 24K 集合的限制,并且我认为该限制目前是可以容忍的。
如果您能提供任何有助于我做出选择的反馈,我将不胜感激。
谢谢和欢呼, 格奥尔格
I'd like to use MongoDB to store my users location history (with their consent, of course). I see the following three options:
- Create one locations collection for all users. Each document would have a userId field, as well as a time field, both of which would be indexed. The number of rows in this collection could potentially grow beyond 100 million.
- Create one collection with users which have their locations as embedded array. That makes searching for locations a little more difficult, since MongoDB apparently doesn't support queries which return embedded documents.
- Create one collection per user with his/her location history. I'm aware of the limit of 24K collections for one MongoDB instance and I think that limit is tolerable for now.
I'd appreciate any feedback which helps me making the choice.
Thanks and cheers,
Georg
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如上面评论中提到的,我选择了选项 1,目前并不后悔。感谢您的帮助。
干杯,
格奥尔格
As mentioned in the comments above, I've chosen option 1 and have no regrets at this point. Thanks for your help.
Cheers,
Georg