docker files fixes from liaqat
This commit is contained in:
20
src/Managing.Infrastructure.Database/MongoDb/MongoHelpers.cs
Normal file
20
src/Managing.Infrastructure.Database/MongoDb/MongoHelpers.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace Managing.Infrastructure.Databases.MongoDb
|
||||
{
|
||||
public static class MongoHelpers
|
||||
{
|
||||
public static async Task EnsureIndexExists(this IMongoDatabase database, string collectionName, string indexName)
|
||||
{
|
||||
var collection = database.GetCollection<BsonDocument>(collectionName);
|
||||
var index = new BsonDocument
|
||||
{
|
||||
{indexName, 1}
|
||||
};
|
||||
|
||||
var indexModel = new CreateIndexModel<BsonDocument>(index, new CreateIndexOptions { Unique = true });
|
||||
await collection.Indexes.CreateOneAsync(indexModel).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user