public PhonebookDbContext(IPhonebookDatabaseSettings phonebookDatabaseSettings)
        {
            var client   = new MongoClient(phonebookDatabaseSettings.ConnectionString);
            var database = client.GetDatabase(phonebookDatabaseSettings.DatabaseName);

            Reports = database.GetCollection <ReportEntity>(phonebookDatabaseSettings.CollectionName);

            //seed data
            PhonebookDbSeedData.SeedData(Reports);
        }
예제 #2
0
        public ContactService(IPhonebookDatabaseSettings settings)
        {
            var client   = new MongoClient(settings.ConnectionString);
            var database = client.GetDatabase(settings.DatabaseName);

            _contacts = database.GetCollection <Contact>(settings.ContactsCollectionName);


            _contacts.Indexes.CreateOne(new CreateIndexModel <Contact>(
                                            Builders <Contact> .IndexKeys.Text(c => c.FirstName).Text(c => c.LastName).Text(c => c.PhoneNumber)
                                            // Builders<Contact>.IndexKeys.Text(c => $"{nameof(Contact).nameof(c.FirstName)} + {nameof(c.LastName)}")
                                            ));
        }