public void CreateUserDeliveryTypeSettingsIndex()
        {
            IndexKeysDefinition<UserDeliveryTypeSettings<ObjectId>> userIndex = Builders<UserDeliveryTypeSettings<ObjectId>>.IndexKeys
                .Ascending(p => p.UserID);

            CreateIndexOptions userOptions = new CreateIndexOptions()
            {
                Name = "UserID",
                Unique = false
            };


            IndexKeysDefinition<UserDeliveryTypeSettings<ObjectId>> addressIndex = Builders<UserDeliveryTypeSettings<ObjectId>>.IndexKeys
                .Ascending(p => p.Address);

            CreateIndexOptions addressOptions = new CreateIndexOptions()
            {
                Name = "Address",
                Unique = false
            };


            IMongoCollection<UserDeliveryTypeSettings<ObjectId>> collection = Context.UserDeliveryTypeSettings;
            collection.Indexes.DropAllAsync().Wait();

            string userName = collection.Indexes.CreateOneAsync(userIndex, userOptions).Result;
            string addressName = collection.Indexes.CreateOneAsync(addressIndex, addressOptions).Result;
        }
Exemplo n.º 2
0
        public virtual string CreateOne(IndexKeysDefinition <TDocument> keys, CreateIndexOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var model  = new CreateIndexModel <TDocument>(keys, options);
            var result = CreateMany(new[] { model }, cancellationToken);

            return(result.Single());
        }
Exemplo n.º 3
0
        public Task CreateIndexAsync(object keys, CreateIndexOptions options, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(keys, "keys");

            var keysDocument = ConvertToBsonDocument(keys);

            options = options ?? new CreateIndexOptions();
            var request = new CreateIndexRequest(keysDocument)
            {
                Name             = options.Name,
                Background       = options.Background,
                Bits             = options.Bits,
                BucketSize       = options.BucketSize,
                DefaultLanguage  = options.DefaultLanguage,
                ExpireAfter      = options.ExpireAfter,
                LanguageOverride = options.LanguageOverride,
                Max                = options.Max,
                Min                = options.Min,
                Sparse             = options.Sparse,
                SphereIndexVersion = options.SphereIndexVersion,
                StorageOptions     = ConvertToBsonDocument(options.StorageOptions),
                TextIndexVersion   = options.TextIndexVersion,
                Unique             = options.Unique,
                Version            = options.Version,
                Weights            = ConvertToBsonDocument(options.Weights)
            };

            var operation = new CreateIndexesOperation(_collectionNamespace, new[] { request }, _messageEncoderSettings);

            return(ExecuteWriteOperation(operation, cancellationToken));
        }
Exemplo n.º 4
0
        public static void EnsureHRIDIndex(IMongoCollection<HRIDEntity> hridCollection)
        {
            var hridIndexOptions = new CreateIndexOptions();
            hridIndexOptions.Unique = true;

            hridCollection.Indexes.CreateOne(Builders<HRIDEntity>.IndexKeys.Ascending(x=>x.HRID), hridIndexOptions);
            hridCollection.Indexes.CreateOne(Builders<HRIDEntity>.IndexKeys.Descending(x => x.HRID), hridIndexOptions);
        }
Exemplo n.º 5
0
        public static void EnsureUniqueIndexOnPhoneNumber(IMongoCollection<User> userCollection)
        {
            CreateIndexOptions<User> options = new CreateIndexOptions<User>();
            options.Unique = true;
            options.Sparse = true;

            userCollection.Indexes.CreateOne(Builders<User>.IndexKeys.Ascending(x => x.PhoneNumber), options);
        }
        public async Task CreateDatabase(bool expireUsingIndex = true)
        {
            var cursor = await _db.ListCollectionsAsync();
            var list = await cursor.ToListAsync();

            if (list.CollectionExists(_settings.ClientCollection))
            {
                await _db.CreateCollectionAsync(_settings.ClientCollection);
            }
            if (!list.CollectionExists(_settings.ScopeCollection))
            {
                await _db.CreateCollectionAsync(_settings.ScopeCollection);
            }
            if (!list.CollectionExists(_settings.ConsentCollection))
            {
                var collection = _db.GetCollection<BsonDocument>(_settings.ConsentCollection);

                await collection.Indexes.CreateOneAsync("subject");


                await collection.Indexes.CreateOneAsync(Builder.IndexKeys.Combine("clientId", "subject"));

            }

            var tokenCollections = new[]
            {
                _settings.AuthorizationCodeCollection,
                _settings.RefreshTokenCollection,
                _settings.TokenHandleCollection
            };

            foreach (string tokenCollection in tokenCollections)
            {
                IMongoCollection<BsonDocument> collection = _db.GetCollection<BsonDocument>(tokenCollection);
                var options = new CreateIndexOptions() {ExpireAfter = TimeSpan.FromSeconds(1)};
                

                await collection.Indexes.CreateOneAsync(Builder.IndexKeys.Combine("_clientId", "_subjectId"));
                
                try
                {
                    await collection.Indexes.CreateOneAsync(Builder.IndexKeys
                        .Ascending("_expires"),
                        options);
                }
                catch (MongoWriteConcernException)
                {
                    await collection.Indexes.DropOneAsync("_expires");
                    await collection.Indexes.CreateOneAsync(Builder.IndexKeys
                    .Ascending("_expires"),
                    options);
                }
            }
        }
        public async Task CreateIndexAsync_should_execute_the_CreateIndexesOperation()
        {
            var keys           = new BsonDocument("x", 1);
            var weights        = new BsonDocument("y", 1);
            var storageOptions = new BsonDocument("awesome", true);
            var options        = new CreateIndexOptions
            {
                Background       = true,
                Bits             = 10,
                BucketSize       = 20,
                DefaultLanguage  = "en",
                ExpireAfter      = TimeSpan.FromSeconds(20),
                LanguageOverride = "es",
                Max                = 30,
                Min                = 40,
                Name               = "awesome",
                Sparse             = false,
                SphereIndexVersion = 50,
                StorageOptions     = storageOptions,
                TextIndexVersion   = 60,
                Unique             = true,
                Version            = 70,
                Weights            = weights
            };
            await _subject.CreateIndexAsync(keys, options, CancellationToken.None);

            var call = _operationExecutor.GetWriteCall <BsonDocument>();

            call.Operation.Should().BeOfType <CreateIndexesOperation>();
            var operation = (CreateIndexesOperation)call.Operation;

            operation.CollectionNamespace.FullName.Should().Be("foo.bar");
            operation.Requests.Count().Should().Be(1);
            var request = operation.Requests.Single();

            request.AdditionalOptions.Should().BeNull();
            request.Background.Should().Be(options.Background);
            request.Bits.Should().Be(options.Bits);
            request.BucketSize.Should().Be(options.BucketSize);
            request.DefaultLanguage.Should().Be(options.DefaultLanguage);
            request.ExpireAfter.Should().Be(options.ExpireAfter);
            request.Keys.Should().Be(keys);
            request.LanguageOverride.Should().Be(options.LanguageOverride);
            request.Max.Should().Be(options.Max);
            request.Min.Should().Be(options.Min);
            request.Name.Should().Be(options.Name);
            request.Sparse.Should().Be(options.Sparse);
            request.SphereIndexVersion.Should().Be(options.SphereIndexVersion);
            request.StorageOptions.Should().Be(storageOptions);
            request.TextIndexVersion.Should().Be(options.TextIndexVersion);
            request.Unique.Should().Be(options.Unique);
            request.Version.Should().Be(options.Version);
            request.Weights.Should().Be(weights);
        }
Exemplo n.º 8
0
        public Authentication(string databaseUrl)
        {
            _userAccounts =
                DatabaseHelper.GetCollection<UserAccount>(databaseUrl);

            _userTokens = DatabaseHelper.GetCollection<UserToken>(databaseUrl);

            var index = new CreateIndexOptions { ExpireAfter = new TimeSpan(0, 30, 0, 0) };
            var keysDefinitionBuilder = new IndexKeysDefinitionBuilder<UserToken>();
            var indexKeysDef = keysDefinitionBuilder.Ascending(x => x.Created);

            _userTokens.Indexes.CreateOneAsync(indexKeysDef, index);
        }
Exemplo n.º 9
0
        private async Task CreateDocumentCollection()
        {
            _collection = _database.GetCollection<BsonDocument>(_collectionName);
            var options = new CreateIndexOptions();
            options.Sparse = true;
            options.Unique = true;

            _collection.Indexes.CreateOneAsync(GetIndexDefinition(), options);

            //await LogIndexes();

            await CreateDocuments();
        }
        public void CreateUserDeliveryTypeSettingsGroupIDIndex()
        {
            IndexKeysDefinition<UserDeliveryTypeSettings<ObjectId>> groupIdIndex = Builders<UserDeliveryTypeSettings<ObjectId>>.IndexKeys
                .Ascending(p => p.GroupID);

            CreateIndexOptions groupIdOptions = new CreateIndexOptions()
            {
                Name = "GroupID",
                Unique = false
            };
            

            IMongoCollection<UserDeliveryTypeSettings<ObjectId>> collection = Context.UserDeliveryTypeSettings;
            collection.Indexes.DropAllAsync().Wait();

            string userName = collection.Indexes.CreateOneAsync(groupIdIndex, groupIdOptions).Result;
        }
        //Alternative
        public void CreateCommentsAddtimeIndex()
        {
            //post
            IndexKeysDefinition<Comment<ObjectId>> articleIndex = Builders<Comment<ObjectId>>.IndexKeys
                .Ascending(p => p.ContentID)
                .Ascending(p => p.AddTimeUtc);

            CreateIndexOptions articleOptions = new CreateIndexOptions()
            {
                Name = "ContentID + AddTimeUtc",
                Unique = false
            };

            //user
            IndexKeysDefinition<Comment<ObjectId>> userIndex = Builders<Comment<ObjectId>>.IndexKeys
               .Ascending(p => p.AuthorID)
               .Ascending(p => p.AddTimeUtc);

            CreateIndexOptions userOptions = new CreateIndexOptions()
            {
                Name = "AuthorID + AddTimeUtc",
                Unique = false
            };

            //addtime
            IndexKeysDefinition<Comment<ObjectId>> addTimeIndex = Builders<Comment<ObjectId>>.IndexKeys
               .Ascending(p => p.AddTimeUtc);

            CreateIndexOptions addTimeOptions = new CreateIndexOptions()
            {
                Name = "AddTimeUtc",
                Unique = false
            };

            IMongoCollection<Comment<ObjectId>> collection = Context.Comments;
            collection.Indexes.DropAllAsync().Wait();

            string articleName = collection.Indexes.CreateOneAsync(articleIndex, articleOptions).Result;
            string userName = collection.Indexes.CreateOneAsync(userIndex, userOptions).Result;
            string addTimeName = collection.Indexes.CreateOneAsync(addTimeIndex, addTimeOptions).Result;
        }
Exemplo n.º 12
0
        public static void EnsureJobIndexes(IMongoCollection<Job> jobCollection)
        {
            //Time Based indexes
            CreateIndexOptions<Job> options = new CreateIndexOptions<Job>();
            options.Background = true;

            List<CreateIndexModel<Job>> TimeIndexes = new List<CreateIndexModel<Job>>();

            var ascendCreateTime = new CreateIndexModel<Job>(Builders<Job>.IndexKeys.Ascending(x => x.CreateTime), options);
            TimeIndexes.Add(ascendCreateTime);

            var descendCreateTime = new CreateIndexModel<Job>(Builders<Job>.IndexKeys.Descending(x => x.CreateTime), options);
            TimeIndexes.Add(descendCreateTime);

            var ascendModifiedTime = new CreateIndexModel<Job>(Builders<Job>.IndexKeys.Ascending(x => x.ModifiedTime), options);
            TimeIndexes.Add(ascendModifiedTime);

            var descendModifiedTime = new CreateIndexModel<Job>(Builders<Job>.IndexKeys.Descending(x => x.ModifiedTime), options);
            TimeIndexes.Add(descendModifiedTime);

            jobCollection.Indexes.CreateMany(TimeIndexes);

            //JobState Index
            List<CreateIndexModel<Job>> BackgroundIndexes = new List<CreateIndexModel<Job>>();

            var ascendJobState = new CreateIndexModel<Job>(Builders<Job>.IndexKeys.Ascending(x=>x.State), options);
            BackgroundIndexes.Add(ascendCreateTime);
            var descendJobState = new CreateIndexModel<Job>(Builders<Job>.IndexKeys.Descending(x => x.State), options);
            BackgroundIndexes.Add(descendCreateTime);

            jobCollection.Indexes.CreateMany(BackgroundIndexes);

            //Geo Indexes
            var geoIndexOptions = new CreateIndexOptions();
            geoIndexOptions.Background = true;
            geoIndexOptions.Sparse = true;

            jobCollection.Indexes.CreateOne(Builders<Job>.IndexKeys.Geo2DSphere(x => x.Order.OrderLocation), geoIndexOptions);
        }
Exemplo n.º 13
0
        public static void EnsureDropPointIndex(IMongoCollection<DropPoint> dropPointCollection)
        {
            dropPointCollection.Indexes.CreateOne(Builders<DropPoint>.IndexKeys.Ascending(x => x.Name));
            dropPointCollection.Indexes.CreateOne(Builders<DropPoint>.IndexKeys.Descending(x => x.Name));

            dropPointCollection.Indexes.CreateOne(Builders<DropPoint>.IndexKeys.Ascending(x => x.UserId));
            dropPointCollection.Indexes.CreateOne(Builders<DropPoint>.IndexKeys.Descending(x => x.UserId));

            dropPointCollection.Indexes.CreateOne(Builders<DropPoint>.IndexKeys.Descending(x => x.UserId));

            var combinedIndexOptions = new CreateIndexOptions();
            combinedIndexOptions.Unique = true;

            dropPointCollection.Indexes.CreateOne(Builders<DropPoint>.IndexKeys.Ascending(x => x.UserId).Ascending(x => x.Name), combinedIndexOptions);
            dropPointCollection.Indexes.CreateOne(Builders<DropPoint>.IndexKeys.Descending(x => x.UserId).Descending(x => x.Name), combinedIndexOptions);


            var geoIndexOptions = new CreateIndexOptions();
            geoIndexOptions.Background = true;
            geoIndexOptions.Sparse = true;

            dropPointCollection.Indexes.CreateOne(Builders<DropPoint>.IndexKeys.Geo2DSphere(x => x.Address.Point), geoIndexOptions);

        }
        public void CreateSignalBounceIndex()
        {
            IndexKeysDefinition<SignalBounce<ObjectId>> userIndex = Builders<SignalBounce<ObjectId>>.IndexKeys
               .Ascending(p => p.ReceiverUserID)
               .Ascending(p => p.BounceReceiveDateUtc);

            CreateIndexOptions userOptions = new CreateIndexOptions()
            {
                Name = "ReceiverUserID + BounceReceiveDateUtc",
                Unique = false
            };


            IMongoCollection<SignalBounce<ObjectId>> collection = Context.SignalBounces;
            collection.Indexes.DropAllAsync().Wait();

            string userName = collection.Indexes.CreateOneAsync(userIndex, userOptions).Result;

        }
        public void CreateSignalDispatchIndex()
        {
            var sendDateIndex = Builders<SignalDispatchBase<ObjectId>>.IndexKeys
               .Ascending(p => p.SendDateUtc)
               .Ascending(p => p.DeliveryType)
               .Ascending(p => p.FailedAttempts);

            CreateIndexOptions sendDateOptions = new CreateIndexOptions()
            {
                Name = "SendDateUtc + DeliveryType + FailedAttempts",
                Unique = false
            };


            var receiverIndex = Builders<SignalDispatchBase<ObjectId>>.IndexKeys
               .Ascending(p => p.ReceiverUserID);

            CreateIndexOptions receiverOptions = new CreateIndexOptions()
            {
                Name = "ReceiverUserID",
                Unique = false
            };


            IMongoCollection<SignalDispatchBase<ObjectId>> collection = Context.SignalDispatches;
            collection.Indexes.DropAllAsync().Wait();

            string sendDateName = collection.Indexes.CreateOneAsync(sendDateIndex, sendDateOptions).Result;
            string receiverName = collection.Indexes.CreateOneAsync(receiverIndex, receiverOptions).Result;

        }
        public void CreateSignalEventIndex()
        {
            var sendDateIndex = Builders<SignalEventBase<ObjectId>>.IndexKeys
               .Ascending(p => p.ReceiveDateUtc)
               .Ascending(p => p.FailedAttempts);

            CreateIndexOptions receiveDateOptions = new CreateIndexOptions()
            {
                Name = "ReceiveDateUtc + CategoryID + FailedAttempts",
                Unique = false
            };
                        
            IMongoCollection<SignalEventBase<ObjectId>> collection = Context.SignalEvents;
            collection.Indexes.DropAllAsync().Wait();

            string receiveDateName = collection.Indexes.CreateOneAsync(sendDateIndex, receiveDateOptions).Result;
        }
        public void CreateUserReceivePeriodsIndex()
        {
            IndexKeysDefinition<UserReceivePeriod<ObjectId>> userIndex = Builders<UserReceivePeriod<ObjectId>>.IndexKeys
                .Ascending(p => p.UserID)
                .Ascending(p => p.ReceivePeriodsGroupID);

            CreateIndexOptions userOptions = new CreateIndexOptions()
            {
                Name = "UserID + ReceivePeriodsGroupID",
                Unique = false
            };


            IMongoCollection<UserReceivePeriod<ObjectId>> collection = Context.UserReceivePeriods;
            collection.Indexes.DropAllAsync().Wait();

            string userName = collection.Indexes.CreateOneAsync(userIndex, userOptions).Result;
        }
Exemplo n.º 18
0
        public static void EnsureVendorIndex(IMongoCollection<Vendor> vendorProfileCollection)
        {
            var UniqueIndexOptions = new CreateIndexOptions();
            UniqueIndexOptions.Unique = true;

            vendorProfileCollection.Indexes.CreateOne(Builders<Vendor>.IndexKeys.Ascending(x => x.UserId), UniqueIndexOptions);
            vendorProfileCollection.Indexes.CreateOne(Builders<Vendor>.IndexKeys.Descending(x => x.UserId), UniqueIndexOptions);
        }
Exemplo n.º 19
0
        private void DequeueIndex(IMongoCollection<Message> collection)
        {
            var dequeueIndex = Builders<Message>.IndexKeys
                .Ascending(m => m.Priority)
                .Ascending(m => m.Id);

            var dequeueOptions = new CreateIndexOptions();
            dequeueOptions.Name = "DequeueIndex";

            // fire and forget
            collection.Indexes.CreateOneAsync(dequeueIndex, dequeueOptions)
                .ContinueWith(LogTaskError, TaskContinuationOptions.OnlyOnFaulted);
        }
Exemplo n.º 20
0
        private void ExpireIndex(IMongoCollection<Message> collection)
        {
            var expireIndex = Builders<Message>.IndexKeys
                .Ascending(m => m.Expire);

            var expireOptions = new CreateIndexOptions();
            expireOptions.Name = "ExpireIndex";
            expireOptions.ExpireAfter = TimeSpan.FromSeconds(1);

            // fire and forget
            collection.Indexes.CreateOneAsync(expireIndex, expireOptions)
                .ContinueWith(LogTaskError, TaskContinuationOptions.OnlyOnFaulted);
        }
Exemplo n.º 21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CreateIndexModel{TDocument}"/> class.
 /// </summary>
 /// <param name="keys">The keys.</param>
 /// <param name="options">The options.</param>
 public CreateIndexModel(IndexKeysDefinition <TDocument> keys, CreateIndexOptions options = null)
 {
     _keys    = Ensure.IsNotNull(keys, nameof(keys));
     _options = CreateIndexOptions <TDocument> .CoercedFrom(options);
 }
Exemplo n.º 22
0
        public static void EnsureProductCategoriesIndex(IMongoCollection<ProductCategory> productCategoryCollection)
        {
            var UniqueIndexOptions = new CreateIndexOptions();
            UniqueIndexOptions.Unique = true;

            productCategoryCollection.Indexes.CreateOne(Builders<ProductCategory>.IndexKeys.Ascending(c => c.Name), UniqueIndexOptions);
            productCategoryCollection.Indexes.CreateOne(Builders<ProductCategory>.IndexKeys.Descending(c => c.Name), UniqueIndexOptions);
        }
        public void CreateComposerSettingsIndex()
        {
            IndexKeysDefinition<ComposerSettings<ObjectId>> userIndex = Builders<ComposerSettings<ObjectId>>.IndexKeys
               .Ascending(p => p.CategoryID);

            CreateIndexOptions userOptions = new CreateIndexOptions()
            {
                Name = "CategoryID",
                Unique = false
            };


            IMongoCollection<ComposerSettings<ObjectId>> collection = Context.ComposerSettings;
            collection.Indexes.DropAllAsync().Wait();

            string userName = collection.Indexes.CreateOneAsync(userIndex, userOptions).Result;

        }
        public void CreateCommentVotesIndex()
        {
            //commentID
            IndexKeysDefinition<CommentVote<ObjectId>> index = Builders<CommentVote<ObjectId>>.IndexKeys
               .Ascending(p => p.CommentID)
               .Ascending(p => p.UserID);

            CreateIndexOptions options = new CreateIndexOptions()
            {
                Name = "CommentID + UserID",
                Unique = true
            };

            IMongoCollection<CommentVote<ObjectId>> collection = Context.CommentVotes;
            collection.Indexes.DropAllAsync().Wait();

            string name = collection.Indexes.CreateOneAsync(index, options).Result;
        }
        public void CreatePostsIndex()
        {
            //category index
            IndexKeysDefinition<ContentBase<ObjectId>> categoryIndex = Builders<ContentBase<ObjectId>>.IndexKeys
               .Ascending(p => p.PublishTimeUtc)
               .Ascending(p => p.IsPublished)
               .Ascending(p => p.CategoryID);

            //время должно быть уникальным, чтобы запрашивать продолжение листа
            CreateIndexOptions categoryOptions = new CreateIndexOptions()
            {
                Name = "PublishTimeUtc + IsPublished + CategoryID",
                Unique = false
            };

            //url index
            IndexKeysDefinition<ContentBase<ObjectId>> urlIndex = Builders<ContentBase<ObjectId>>.IndexKeys
               .Ascending(p => p.Url);

            CreateIndexOptions urlOptions = new CreateIndexOptions()
            {
                Name = "Url",
                Unique = true
            };

            IMongoCollection<ContentBase<ObjectId>> collection = Context.Posts;
            collection.Indexes.DropAllAsync().Wait();

            string categoryName = collection.Indexes.CreateOneAsync(categoryIndex, categoryOptions).Result;

            string urlName = collection.Indexes.CreateOneAsync(urlIndex, urlOptions).Result;
        }
        public void CreateUserCategorySettingsIndex(bool useGroupID)
        {
            IndexKeysDefinition<UserCategorySettings<ObjectId>> userIndex = Builders<UserCategorySettings<ObjectId>>.IndexKeys
                .Ascending(p => p.UserID);

            CreateIndexOptions userOptions = new CreateIndexOptions()
            {
                Name = "UserID",
                Unique = false
            };

            IndexKeysDefinition<UserCategorySettings<ObjectId>> categoryIndex = null;            
            if(useGroupID)
            {
                categoryIndex = Builders<UserCategorySettings<ObjectId>>.IndexKeys
                    .Ascending(p => p.GroupID)
                    .Ascending(p => p.CategoryID);
            }
            else
            {
                categoryIndex = Builders<UserCategorySettings<ObjectId>>.IndexKeys
                    .Ascending(p => p.CategoryID);
            }

            CreateIndexOptions categoryOptions = new CreateIndexOptions()
            {
                Name = "CategoryID",
                Unique = false
            };

            IMongoCollection<UserCategorySettings<ObjectId>> collection = Context.UserCategorySettings;
            collection.Indexes.DropAllAsync().Wait();

            string userName = collection.Indexes.CreateOneAsync(userIndex, userOptions).Result;
            string categoryName = collection.Indexes.CreateOneAsync(categoryIndex, categoryOptions).Result;

        }
Exemplo n.º 27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CreateIndexModel{TDocument}"/> class.
 /// </summary>
 /// <param name="keys">The keys.</param>
 /// <param name="options">The options.</param>
 public CreateIndexModel(IndexKeysDefinition <TDocument> keys, CreateIndexOptions options = null)
 {
     _keys    = Ensure.IsNotNull(keys, "keys");
     _options = options;
 }
Exemplo n.º 28
0
        private void TimeoutIndex(IMongoCollection<Message> collection)
        {
            var timeoutIndex = Builders<Message>.IndexKeys
                .Ascending("State") // issue with enum type
                .Ascending(m => m.Updated);

            var timeoutOptions = new CreateIndexOptions();
            timeoutOptions.Name = "TimeoutIndex";

            // fire and forget
            collection.Indexes.CreateOneAsync(timeoutIndex, timeoutOptions)
                .ContinueWith(LogTaskError, TaskContinuationOptions.OnlyOnFaulted);
        }
        public void CreateUserTopicSettingsIndex()
        {
            IndexKeysDefinition<UserTopicSettings<ObjectId>> topicIndex = Builders<UserTopicSettings<ObjectId>>.IndexKeys
                .Ascending(p => p.CategoryID)
                .Ascending(p => p.TopicID);

            CreateIndexOptions topicOptions = new CreateIndexOptions()
            {
                Name = "CategoryID + TopicID",
                Unique = false
            };
            
            IndexKeysDefinition<UserTopicSettings<ObjectId>> userIndex = Builders<UserTopicSettings<ObjectId>>.IndexKeys
                .Ascending(p => p.UserID);

            CreateIndexOptions userOptions = new CreateIndexOptions()
            {
                Name = "UserID",
                Unique = false
            };


            IMongoCollection<UserTopicSettings<ObjectId>> collection = Context.UserTopicSettings;
            collection.Indexes.DropAllAsync().Wait();

            string topicName = collection.Indexes.CreateOneAsync(topicIndex, topicOptions).Result;
            string userName = collection.Indexes.CreateOneAsync(userIndex, userOptions).Result;

        }
Exemplo n.º 30
0
        private void StateIndex(IMongoCollection<Message> collection)
        {
            var stateIndex = Builders<Message>.IndexKeys
                .Ascending("State"); // issue with enum type

            var stateOptions = new CreateIndexOptions();
            stateOptions.Name = "StateIndex";

            // fire and forget
            collection.Indexes.CreateOneAsync(stateIndex, stateOptions)
                .ContinueWith(LogTaskError, TaskContinuationOptions.OnlyOnFaulted);
        }
 /// <inheritdoc />
 public abstract Task CreateOneAsync(IndexKeysDefinition <TDocument> keys, CreateIndexOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
Exemplo n.º 32
0
        private void DefaultSortIndex(IMongoCollection<Message> collection)
        {
            var index = Builders<Message>.IndexKeys
                .Descending(m => m.Updated);

            var indexOptions = new CreateIndexOptions();
            indexOptions.Name = "DefaultSortIndex";

            // fire and forget
            collection.Indexes.CreateOneAsync(index, indexOptions)
                .ContinueWith(LogTaskError, TaskContinuationOptions.OnlyOnFaulted);
        }
Exemplo n.º 33
0
 public async Task<string> CreateIndexAsync(string databaseName, string collection, BsonDocument indexDefinition, CreateIndexOptions options)
 {
     var db = client.GetDatabase(databaseName);
     var mongoCollection = db.GetCollection<BsonDocument>(collection);
     return await mongoCollection.Indexes.CreateOneAsync(indexDefinition, options);
 }
            public override Task CreateOneAsync(IndexKeysDefinition <TDocument> keys, CreateIndexOptions options, CancellationToken cancellationToken)
            {
                Ensure.IsNotNull(keys, "keys");

                var keysDocument = keys.Render(_collection._documentSerializer, _collection._settings.SerializerRegistry);

                options = options ?? new CreateIndexOptions();
                var request = new CreateIndexRequest(keysDocument)
                {
                    Name             = options.Name,
                    Background       = options.Background,
                    Bits             = options.Bits,
                    BucketSize       = options.BucketSize,
                    DefaultLanguage  = options.DefaultLanguage,
                    ExpireAfter      = options.ExpireAfter,
                    LanguageOverride = options.LanguageOverride,
                    Max                = options.Max,
                    Min                = options.Min,
                    Sparse             = options.Sparse,
                    SphereIndexVersion = options.SphereIndexVersion,
                    StorageEngine      = options.StorageEngine,
                    TextIndexVersion   = options.TextIndexVersion,
                    Unique             = options.Unique,
                    Version            = options.Version,
                    Weights            = options.Weights
                };

                var operation = new CreateIndexesOperation(_collection._collectionNamespace, new[] { request }, _collection._messageEncoderSettings);

                return(_collection.ExecuteWriteOperation(operation, cancellationToken));
            }
        public virtual async Task <string> CreateOneAsync(IndexKeysDefinition <TDocument> keys, CreateIndexOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var model  = new CreateIndexModel <TDocument>(keys, options);
            var result = await CreateManyAsync(new[] { model }, cancellationToken).ConfigureAwait(false);

            return(result.Single());
        }