Ejemplo n.º 1
0
        private static async Task <IMongoCollection <AccommodationAvailabilityResult> > GetOrCreateCollection(IMongoDbClient client)
        {
            var collection = client.GetDatabase().GetCollection <AccommodationAvailabilityResult>(nameof(AccommodationAvailabilityResult));

            var searchIndexDefinition = Builders <AccommodationAvailabilityResult> .IndexKeys.Combine(
                Builders <AccommodationAvailabilityResult> .IndexKeys.Ascending(f => f.SearchId),
                Builders <AccommodationAvailabilityResult> .IndexKeys.Ascending(f => f.Supplier));

            var ttlIndexDefinition = Builders <AccommodationAvailabilityResult> .IndexKeys.Ascending(f => f.Created);

            var ttlIndexOptions = new CreateIndexOptions {
                ExpireAfter = TimeSpan.FromMinutes(RecordTtlInMinutes)
            };

            await collection.Indexes.CreateManyAsync(new []
            {
                new CreateIndexModel <AccommodationAvailabilityResult>(searchIndexDefinition),
                new CreateIndexModel <AccommodationAvailabilityResult>(ttlIndexDefinition, ttlIndexOptions)
            });

            return(collection);
        }
Ejemplo n.º 2
0
        public TitlesService(IMongoDbClient client)
        {
            var database = client.GetDatabase();

            _titlesCollection = database.GetCollection <Title>("Titles");
        }