Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个集合users,其文件将属于 a company(每个公司可以有很多users)。因为我对公司名称设置了唯一索引,所以我可以使用名称作为user文档内部的外键,还是建议使用 id 代替?
users
company
user
如果名称是唯一的并且保证永远不会更改,那么您可以使用它,没问题。尽管在我的实践中,有时名称变得不那么独特且不那么不变(该死的要求更改)。因此,为了更加安全,请使用 id。