From 0184481a7f8911fa09fcc1c4df40295c9383bffe Mon Sep 17 00:00:00 2001 From: John Lyon-Smith Date: Tue, 24 Apr 2018 09:54:43 -0700 Subject: [PATCH] Fix indexes for users --- server/src/database/schemas/user.js | 40 ++++++++++++++++------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/server/src/database/schemas/user.js b/server/src/database/schemas/user.js index 8f3677b..fb14178 100644 --- a/server/src/database/schemas/user.js +++ b/server/src/database/schemas/user.js @@ -4,12 +4,7 @@ import { regExpPattern } from "regexp-pattern" export let userSchema = new Schema( { _id: { type: Schema.Types.ObjectId, required: true, auto: true }, - loginToken: { - type: String, - index: true, - unique: true, - partialFilterExpression: { loginToken: { $type: "string" } }, - }, + loginToken: String, passwordHash: { type: { hash: String, @@ -30,23 +25,13 @@ export let userSchema = new Schema( thumbnailImageId: { type: Schema.Types.ObjectId }, emailToken: { type: { - value: { - type: String, - index: true, - unique: true, - partialFilterExpression: { emailToken: { $type: "string" } }, - }, + value: String, created: Date, }, }, passwordToken: { type: { - value: { - type: String, - index: true, - unique: true, - partialFilterExpression: { passwordToken: { $type: "string" } }, - }, + value: String, created: Date, }, }, @@ -58,6 +43,25 @@ export let userSchema = new Schema( { 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) { if (!authUser) { authUser = this