Fix indexes for users

This commit is contained in:
John Lyon-Smith
2018-04-24 09:54:43 -07:00
parent 680f7befaa
commit 0184481a7f

View File

@@ -4,12 +4,7 @@ import { regExpPattern } from "regexp-pattern"
export let userSchema = new Schema( export let userSchema = new Schema(
{ {
_id: { type: Schema.Types.ObjectId, required: true, auto: true }, _id: { type: Schema.Types.ObjectId, required: true, auto: true },
loginToken: { loginToken: String,
type: String,
index: true,
unique: true,
partialFilterExpression: { loginToken: { $type: "string" } },
},
passwordHash: { passwordHash: {
type: { type: {
hash: String, hash: String,
@@ -30,23 +25,13 @@ export let userSchema = new Schema(
thumbnailImageId: { type: Schema.Types.ObjectId }, thumbnailImageId: { type: Schema.Types.ObjectId },
emailToken: { emailToken: {
type: { type: {
value: { value: String,
type: String,
index: true,
unique: true,
partialFilterExpression: { emailToken: { $type: "string" } },
},
created: Date, created: Date,
}, },
}, },
passwordToken: { passwordToken: {
type: { type: {
value: { value: String,
type: String,
index: true,
unique: true,
partialFilterExpression: { passwordToken: { $type: "string" } },
},
created: Date, created: Date,
}, },
}, },
@@ -58,6 +43,25 @@ export let userSchema = new Schema(
{ timestamps: true, id: false } { timestamps: true, id: false }
) )
userSchema.index(
{ "emailToken.value": 1 },
{
unique: true,
partialFilterExpression: { "emailToken.value": { $type: "string" } },
}
)
userSchema.index(
{ "passwordToken.value": 1 },
{
unique: true,
partialFilterExpression: { "passwordToken.value": { $type: "string" } },
}
)
userSchema.index(
{ loginToken: 1 },
{ unique: true, partialFilterExpression: { loginToken: { $type: "string" } } }
)
userSchema.methods.toClient = function(authUser) { userSchema.methods.toClient = function(authUser) {
if (!authUser) { if (!authUser) {
authUser = this authUser = this