用于处理不区分大小写的MongoDB模式

时间:2014-03-03 03:33:49

标签: mongodb database-schema

我有用户集合。由于MongoDB区分大小写,我需要重新考虑我的架构,我可以像SQL Server一样以不敏感的方式处理用户名。

MongoDB区分大小写是问题的根源!!

Schema 1:
_id   LowerCaseUserName  email         pwd
Bob   bob                bob@xy.com    ---    
iSpy  ispy               ispy@abc.com  ---

Notes on schema 1:    
 A) There is only one index on _id field in schema 2  
 B) _id is what user entered during signup & shown in URL and pages  
 C) _id is BsonId and app guarantees uniqueness.
 D) There is an index on LowerCaseUserName field & another on email field

Schema 2:
_id   ActualUserName  email            pwd
bob   Bob                bob@xy.com    ---
ispy  iSpy               ispy@abc.com  ---

Notes on schema 2:    
 A) ActualUserName is what user entered during signup & shown in URL and pages    
 B) _id is lowercase of ActualUserName (BsonId) & app guarantees uniqueness   
 C) _id is BsonId andd guaranteed to be unique
 D) There is an index on email field as well

这些是要支持的查询:

I) Find if username and password matches (Login)
   The username entered must be treated as case insensitive
2) Check if a username already taken (during new user signup)
3) Check if a given email is already used
4) Update Account
5) Update password
6) Update email

您认为哪种架构可以为我提供更好的性能,并且可以很好地扩展到集合中的大量用户?

如果您需要进一步澄清,请告诉我您的想法。

谢谢

0 个答案:

没有答案