public FoodItemService(IFoodSharingDatabaseSettings settings, DatabaseService databaseService) { _items = databaseService.Database.GetCollection <FoodItem>(settings.ItemsCollectionName); var indexOptions = new CreateIndexOptions { Background = false }; var indexKeys = Builders <FoodItem> .IndexKeys.Geo2DSphere(item => item.Position); _items.Indexes.CreateOne(new CreateIndexModel <FoodItem>(indexKeys, indexOptions)); }
public DatabaseService(IFoodSharingDatabaseSettings settings) { var credential = MongoCredential.CreateCredential(settings.MasterDatabaseName, settings.DatabaseUser, settings.DatabasePassword); var mongoClientSettings = new MongoClientSettings { Credential = credential, Server = new MongoServerAddress(settings.DatabaseServer, settings.DatabasePort) }; var client = new MongoClient(mongoClientSettings); Database = client.GetDatabase(settings.DatabaseName); }
public UserService(IFoodSharingDatabaseSettings settings, DatabaseService databaseService) { _items = databaseService.Database.GetCollection <User>(settings.UsersCollectionName); }