我很长时间以来一直对 MongoDB 有同样的问题。因此,我尝试为邀请我的不和谐机器人加入其公会的用户存储一些用户数据。它根据行会 ID 和用户 ID 存储它们,因为一个用户可能位于具有同一机器人的多个服务器中。我想知道为每个行会制作一份文档并将每个用户添加到该文档中是否正确,或者我应该为每个用户制作一份带有行会 ID 密钥和用户 ID 密钥的单独文档。
例如,我在这篇文章中附加了两张照片,第一张照片的特点是一个文档,其中“用户”字段嵌套在一个对象中,该对象的键作为用于查询的行会 ID。第二个功能是为每个用户提供一个单独的文档,并具有用于查询的单独的“用户 ID”和“行会 ID”密钥。
单个文档文件
多文档文件
感谢任何和所有帮助。先感谢您。
I've been having this same question about MongoDB for the longest time. So I'm trying to store some user data for users who invite my discord bot to their guild. It stores them based off guild ID and user ID, because one user could be in multiple servers with the same bot. I was wondering if it would be correct to make one document for each guild and add every user to that one document, or should I make a separate document for each user with a guild ID key and user ID key.
For example I've attached 2 photos to this post, the first features one document with a "Users" field nested into an object with the key as the guild ID used for querying. The second features a separate document for each user with a separate "User ID" and "Guild ID" key used for querying.
Single Document File
Multi Document File
Any and all help is appreciated. Thank you in advance.
发布评论
评论(1)
这是一个你可以做的想法。这样您就可以以任何您喜欢的方式获取数据并聚合,并且不会有任何不必要的嵌套。简单灵活
This is an idea what you can do. This way you can fetch data and aggregate any way you like, and you won't be having any unnecessary nesting. Simple and flexible