Currently when Driver is about to execute any operation we creates appropriate operation on MongoClient/Database/Collection level and IBinding. But inside of the operation execution we usually create another command, that is actually will be executed:
(code taken from CreateIndexesOperation.cs):
public async Task<BsonDocument> ExecuteAsync(OperationContext operationContext, IWriteBinding binding) { using (BeginOperation()) using (var channelSource = await binding.GetWriteChannelSourceAsync(operationContext).ConfigureAwait(false)) using (var channel = await channelSource.GetChannelAsync(operationContext).ConfigureAwait(false)) using (var channelBinding = new ChannelReadWriteBinding(channelSource.Server, channel, binding.Session.Fork())) { var operation = CreateOperation(channelBinding.Session, channel.ConnectionDescription); return await operation.ExecuteAsync(operationContext, channelBinding).ConfigureAwait(false); } }
Moreover operation execution started from IBinding, then we get ChannelSource which we use to create Channel, and then we create new ChannelReadWriteBinding that is using to execute the inner command... But inner command is go though the same circle one more time: IBinding -> channelSource -> channel.
We should review the code and probably eliminate the inner command as it looks redundant now.