用于多策略sigup用户表的架构

在一个项目上工作时,面临不同的护照策略(本地,脸谱,微博)存储用户信息的问题。 在开始我的UserSchema有这样的样子:

  User = mongoose.Schema( { "email" : { type : String , lowercase: true , trim : true , unique : true } , "providerId" : { type : String } , "providerName" : { type : String } , "hashedPassword" : { type : String } , "salt" : { type : String } , "strategy" : { type : String } , "created" : { type : Date , default : new Date().valueOf() } , "lastConnected" : { type : Date , default : new Date().valueOf() } , "accessToken" : { type : String } , "securityToken" : { type : String , default : "" } , "roles" : [ { type : String } ] } ); 

但独特的电子邮件带来了电子邮件的问题,因为两个用户使用twitter stategy将具有空邮件,这会导致错误。

我想过不要让电子邮件独一无二,但这会带来很多问题(从第一眼看)。 我看到的一个解决scheme是为每个策略制定不同的模式,但是这是非常难以维持的。

有没有其他解决这个问题的方法。 什么是最佳实践?

PS我发誓我GOOGLE了,但没有find任何解决scheme

看起来你可以说unique:true和指定allowNulls。 这现在看起来是可能的,你可以看到这里: https : //stackoverflow.com/a/9693138/1935918