Ejemplo n.º 1
0
        public async Task <BsonDocument> ExecuteAsync(IWriteBinding binding, TimeSpan timeout = default(TimeSpan), CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(binding, "binding");
            var indexDocument  = CreateIndexDocument();
            var documentSource = new BatchableSource <BsonDocument>(new[] { indexDocument });
            var operation      = new InsertOpcodeOperation(_databaseName, "system.indexes", documentSource).WithWriteConcern(_writeConcern);

            return(await operation.ExecuteAsync(binding, timeout, cancellationToken));
        }
Ejemplo n.º 2
0
        public async Task <BsonDocument> ExecuteAsync(IWriteBinding binding, TimeSpan timeout = default(TimeSpan), CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(binding, "binding");
            var indexDocument  = CreateIndexDocument();
            var documentSource = new BatchableSource <BsonDocument>(new[] { indexDocument });
            var operation      = new InsertOpcodeOperation(_collectionNamespace.DatabaseNamespace.SystemIndexesCollection, documentSource, _messageEncoderSettings)
            {
                WriteConcern = _writeConcern
            };
            var results = await operation.ExecuteAsync(binding, timeout, cancellationToken).ConfigureAwait(false);

            return(results.First().Response);
        }
        private async Task <BsonDocument> ExecuteUsingInsertAsync(IChannelSourceHandle channelSource, CancellationToken cancellationToken)
        {
            var systemIndexesCollection = _collectionNamespace.DatabaseNamespace.SystemIndexesCollection;

            foreach (var createIndexRequest in _requests)
            {
                var document = createIndexRequest.CreateIndexDocument();
                document.InsertAt(0, new BsonElement("ns", _collectionNamespace.FullName));
                var documentSource = new BatchableSource <BsonDocument>(new[] { document });
                var operation      = new InsertOpcodeOperation(systemIndexesCollection, documentSource, _messageEncoderSettings);
                await operation.ExecuteAsync(channelSource, cancellationToken).ConfigureAwait(false);
            }

            return(new BsonDocument("ok", 1));
        }