From 852b2d7817fd5ee43499f15649db2d9268c79dc4 Mon Sep 17 00:00:00 2001 From: vova3211 Date: Sun, 8 Sep 2024 12:07:38 +0300 Subject: [PATCH] remove default index creation. --- README.md | 22 ++++++++++++++++--- .../Stores/UserStore.cs | 9 -------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 87576fa..e092e24 100644 --- a/README.md +++ b/README.md @@ -20,14 +20,30 @@ This is a MongoDB provider for the ASP.NET Core Identity framework. It is comple * IRoleClaimStore * IQueryableRoleStore -## Dot Net Core Versions support +## Dotnet Versions support -Starting from v9.0.0 library only supports **.Net 6.0** and **.Net 8.0** as they are -only versions maintainable by Microsoft. [Supported Dotnet Versions](https://dotnet.microsoft.com/en-us/download/dotnet) +Starting from `v9.0.0` library only supports **.Net 6.0** and **.Net 8.0** as they are +only versions maintainable by Microsoft at the moment. [Supported Dotnet Versions](https://dotnet.microsoft.com/en-us/download/dotnet) Library supports **.Net 6.0**, **.Net 5.0**, **.Net Core 3.1**, **.Net Core 2.1** simultaneously started from 8.3.0 nuget package. +## MongoDB Indexes + +**Important note!** + +Starting from `v9.0.0` we no longer apply indexes on `"Users"` collection. Main reason for this change that +you are unable to change default indexes. If you delete index, it will appear again; +if you delete index and re-create it with different options, application won't start due to error. +You most likely have other indexes of your own, and now you have 2 places where they managed. +So it's up to user to decide which indexes should be used (if any), how and where manage them. + +Here the old indexes in case someone needs them (collection name could be different): +``` +db.Users.createIndex({ "NormalizedEmail" : 1 }) +db.Users.createIndex({ "NormalizedUserName" : 1 }) +``` + ## How to use: AspNetCore.Identity.Mongo is installed from NuGet: ``` diff --git a/src/AspNetCore.Identity.Mongo/Stores/UserStore.cs b/src/AspNetCore.Identity.Mongo/Stores/UserStore.cs index 9accdf1..652741f 100644 --- a/src/AspNetCore.Identity.Mongo/Stores/UserStore.cs +++ b/src/AspNetCore.Identity.Mongo/Stores/UserStore.cs @@ -77,9 +77,6 @@ public UserStore(IMongoCollection userCollection, IMongoCollection _userCollection = userCollection; _roleCollection = roleCollection; ErrorDescriber = describer ?? new IdentityErrorDescriber(); - - EnsureIndex(x => x.NormalizedEmail); - EnsureIndex(x => x.NormalizedUserName); } /// @@ -1262,12 +1259,6 @@ private async Task> FindTokenAsync(TUser user, string return dbUser?.Tokens?.FirstOrDefault(x => x.LoginProvider == loginProvider && x.Name == name); } - private void EnsureIndex(Expression> field) - { - var model = new CreateIndexModel(Builders.IndexKeys.Ascending(field)); - _userCollection.Indexes.CreateOne(model); - } - private async Task UpdateAsync(TUser user, Expression> expression, TFieldValue value, CancellationToken cancellationToken = default) { if (user == null) throw new ArgumentNullException(nameof(user));