diff --git a/api/models/schema/userSchema.js b/api/models/schema/userSchema.js index 80e635fc60..6b1d010346 100644 --- a/api/models/schema/userSchema.js +++ b/api/models/schema/userSchema.js @@ -51,28 +51,18 @@ const userSchema = mongoose.Schema( }, googleId: { type: String, - unique: true, - sparse: true, }, facebookId: { type: String, - unique: true, - sparse: true, }, openidId: { type: String, - unique: true, - sparse: true, }, githubId: { type: String, - unique: true, - sparse: true, }, discordId: { type: String, - unique: true, - sparse: true, }, plugins: { type: Array, @@ -85,4 +75,25 @@ const userSchema = mongoose.Schema( { timestamps: true }, ); +userSchema.index( + { googleId: 1 }, + { unique: true, partialFilterExpression: { googleId: { $type: 'string' } } }, +); +userSchema.index( + { facebookId: 1 }, + { unique: true, partialFilterExpression: { facebookId: { $type: 'string' } } }, +); +userSchema.index( + { openidId: 1 }, + { unique: true, partialFilterExpression: { openidId: { $type: 'string' } } }, +); +userSchema.index( + { githubId: 1 }, + { unique: true, partialFilterExpression: { githubId: { $type: 'string' } } }, +); +userSchema.index( + { discordId: 1 }, + { unique: true, partialFilterExpression: { discordId: { $type: 'string' } } }, +); + module.exports = userSchema;