设计 MongoDB 模型?

发布于 2025-01-08 15:41:15 字数 293 浏览 0 评论 0原文

我有一个关于在 mongo db 中设计数据模型的概念性问题。 我有一些“列表”的记录。每个列表都是“一行”记录,包含 id、descr、createdBy 等字段。但现在我有一个要求,每个“列表”都可以与其他用户共享。当用户登录查看他创建的“列表”和与他共享的“列表”时,设计/重新设计模型的最佳方法是什么?我正在考虑创建新字段“sharedWith”,其中共享“list”的所有用户名都用逗号(或其他内容)分隔。然后当请求在此字段中搜索时。但不知何故,这种方法在我看来并不是很有用。您能给我一些建议或指导吗? 我正在使用带有猫鼬的nodejs。

谢谢!

i have one conceptual question about designing data model in mongo db.
I have some record for "lists". Each list is "one row" record with id, descr, createdBy etc. fiels. But now i have a requirement that each "list" can be shared with other users. What is the best way to design/re-design the model so when user login to see "lists" that he created and "lists" that was shared with him? I was thinking of creating new field "sharedWith" in which all usernames with which "list" is shared to be put separated with comma(or something else). And then when request is made to search in this field. But somehow this approach doesn't seem to me very useful. Can you give me some advice or guidelines ?
I'm using nodejs with mongoose.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流心雨 2025-01-15 15:41:15
User: {
  ...
  myLists: Array<ListObject>
  sharedLists: Array<ListObject>
};

ListObject: {
  ...
  owner: User,
  sharedWith: Array<User>
};

对我来说,这似乎是一个明智的设计。

User: {
  ...
  myLists: Array<ListObject>
  sharedLists: Array<ListObject>
};

ListObject: {
  ...
  owner: User,
  sharedWith: Array<User>
};

That would seem a sensible design to me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文