Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2224

Subscribe on CommandFailedEvent crush GridFSBucket, GridFSBucket<T> initialization

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.5
    • Component/s: Configuration, GridFS
    • None
    • Environment:
      Net core, ubuntu 16.04, mongodb 3.6.2 version
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

                  builder.Register(ctx => new MongoClient(_mongoClientSettings))
                      .As<IMongoClient>()
                      .SingleInstance();
                  
                  builder.Register(ctx =>
                  {
                      var client = ctx.Resolve<IMongoClient>();
                      
                      return client.GetDatabase(_databaseName);
                  }).As<IMongoDatabase>().SingleInstance();
      
                  builder.Register(
                      ctx => new GridFSBucket<Guid>(
                          ctx.Resolve<IMongoDatabase>(),
                          new GridFSBucketOptions
                          {
                              BucketName = "Avatars"
                          }))
                      .As<IGridFSBucket<Guid>>()
                      .SingleInstance();
      
                  clientSettings.ClusterConfigurator = clusterBuilder =>
                  {
                      clusterBuilder.Subscribe<ClusterSelectingServerFailedEvent>(evnt =>
                          {
                              var logger = loggerFactory.CreateLogger<MongoModule>();
                              logger.LogCritical("Cluster selecting server failed! {@Event}", evnt);
                          })
      //                    .Subscribe<CommandFailedEvent>(evnt =>
      //                    {
      //                        var logger = loggerFactory.CreateLogger<MongoModule>();
      //                        logger.LogWarning("Command failed! {@Event}", evnt);
      //                    })
                          .Subscribe<ConnectionFailedEvent>(evnt =>
                          {
                              var logger = loggerFactory.CreateLogger<MongoModule>();
                              logger.LogCritical("Connection failed! {@Event}", evnt);
                          })
                          .Subscribe<ConnectionOpeningFailedEvent>(evnt =>
                          {
                              var logger = loggerFactory.CreateLogger<MongoModule>();
                              logger.LogCritical("Connection opening failed! {@Event}", evnt);
                          })
                          .Subscribe<ConnectionPoolCheckingOutConnectionFailedEvent>(evnt =>
                          {
                              var logger = loggerFactory.CreateLogger<MongoModule>();
                              logger.LogCritical("Connection pool checking out connection failed! {@Event}", evnt);
                          })
                          .Subscribe<ConnectionReceivingMessageFailedEvent>(evnt =>
                          {
                              var logger = loggerFactory.CreateLogger<MongoModule>();
                              logger.LogWarning("Connection receiving message failed! {@Event}", evnt);
                          })
                          .Subscribe<ConnectionSendingMessagesFailedEvent>(evnt =>
                          {
                              var logger = loggerFactory.CreateLogger<MongoModule>();
                              logger.LogWarning("Connection sending messages failed! {@Event}", evnt);
                          })
                          .Subscribe<ServerHeartbeatFailedEvent>(evnt =>
                          {
                              var logger = loggerFactory.CreateLogger<MongoModule>();
                              logger.LogCritical("Server heart beat failed! {@Event}", evnt);
                          })
                          .Subscribe<ServerClosedEvent>(evnt =>
                          {
                              var logger = loggerFactory.CreateLogger<MongoModule>();
                              logger.LogCritical("Server closed! {@Event}", evnt);
                          })
                          .Subscribe<ServerOpenedEvent>(evnt =>
                          {
                              var logger = loggerFactory.CreateLogger<MongoModule>();
                              logger.LogInformation("Server opened! {@Event}", evnt);
                          })
                          .Subscribe<ConnectionOpenedEvent>(evnt =>
                          {
                              var logger = loggerFactory.CreateLogger<MongoModule>();
                              logger.LogInformation("Connection opened! {@Event}", evnt);
                          });
                  };
      

      If subscription wil be uncomment, any upload operation will be raise CommandFailedEvent with messages:

      `Collection Avatars.files does not exist`
      `Collection Avatars.chunks does not exist`

      After explicitly collections creation all work as expected.

            Assignee:
            james.kovacs@mongodb.com James Kovacs
            Reporter:
            t.myagkikh Timofey Myagkikh
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: