MongoDB 多种用户类型的架构

MongoDB Schema for multiple user types

我的应用程序中存在三种不同的用户类型。 1.Creator 2.Company 3.Admin

这三个字段几乎相同,除了没有全名 company.But 会有公司名称字段。

 id: string;
 email: string;
 phone: string;
 password: string;
 user_type: string;
 full_name: string;
 company_name:string

对于每个用户类型,我应该遵循具有单个集合还是 3 个不同集合的相同架构?

根据我的经验,在这种情况下,从长远来看,坚持使用单个集合然后通过查询进行区分通常会更好。这使您可以在将来轻松添加其他用户类型(您现在无法预见),而无需添加更多集合。