mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 10:20:15 +01:00
refactor(userSchema): unique index definitions using partialFilterExpression instead of sparse
This commit is contained in:
parent
18edd2660b
commit
a1c7110a94
1 changed files with 21 additions and 10 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue