Skip to content

Commit

Permalink
remove default index creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
vova3211 committed Sep 8, 2024
1 parent 785e67f commit 852b2d7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
```
Expand Down
9 changes: 0 additions & 9 deletions src/AspNetCore.Identity.Mongo/Stores/UserStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ public UserStore(IMongoCollection<TUser> userCollection, IMongoCollection<TRole>
_userCollection = userCollection;
_roleCollection = roleCollection;
ErrorDescriber = describer ?? new IdentityErrorDescriber();

EnsureIndex(x => x.NormalizedEmail);
EnsureIndex(x => x.NormalizedUserName);
}

/// <summary>
Expand Down Expand Up @@ -1262,12 +1259,6 @@ private async Task<IdentityUserToken<string>> FindTokenAsync(TUser user, string
return dbUser?.Tokens?.FirstOrDefault(x => x.LoginProvider == loginProvider && x.Name == name);
}

private void EnsureIndex(Expression<Func<TUser, object>> field)
{
var model = new CreateIndexModel<TUser>(Builders<TUser>.IndexKeys.Ascending(field));
_userCollection.Indexes.CreateOne(model);
}

private async Task UpdateAsync<TFieldValue>(TUser user, Expression<Func<TUser, TFieldValue>> expression, TFieldValue value, CancellationToken cancellationToken = default)
{
if (user == null) throw new ArgumentNullException(nameof(user));
Expand Down

0 comments on commit 852b2d7

Please sign in to comment.