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

Logged Command property casing not serializer compatible

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Serialization
    • Labels:
      None

      I am logging commands using

                  // The following will map .NET Pascal Cased properties to bson Camel Cased properties.
                  var conventionPack = new ConventionPack
                  {
                      new CamelCaseElementNameConvention(), new IgnoreExtraElementsConvention(true)
                  };
                  ConventionRegistry.Register("camelCase", conventionPack, t => true);
                  
                  clientSettings.ClusterConfigurator = cb =>
                  {
                      // This makes the output strictly JSON, such that we can format the logged commands.
                      // The output can still be used in a shell (ex NoSqlBooster)
                      // Without this, the output can contain JS code, such a regular expression literals
                      // which would fail to format in a JSON formatter.
                      var jsonWriterSettings = new JsonWriterSettings { OutputMode = JsonOutputMode.Strict };
                      cb.Subscribe<CommandStartedEvent>(e =>
                      {
                          if (_logger.IsEnabled(LogLevel.Debug))
                          {
                              _logger.LogDebug($"MongoDb - {e.CommandName} - {e.Command.ToJson(jsonWriterSettings)}");
                          }
                      });
                  };
      

      This method

      // ...
      .Project(augmentedProductType => new ProductTypeSearchResult
      {
        Description = augmentedProductType.ExternalProductTypeDescription
      })
      

      Results in a logged statement like (theLoggedCommand)

       private const string ProjectionStage = @"
      {
         "$project":{
            "Description":"$externalProductTypeDesc"
         }
      }
      

      But if I then replace the Project method call with the logged command using

       private static readonly PipelineStageDefinition<SearchAugmentedProductType, ProductTypeSearchResult>
                  ProjectionPipelineStageDefinition = "theLoggedCommand";
      .AppendStage(ProjectionPipelineStageDefinition);
      

      Default serialization mapping does not work. I actually have to change the command to have lower case properties.

       private const string ProjectionStage = @"
      {
         "$project":{
            "description":"$externalProductTypeDesc"
         }
      }
      

      I would not expect to have to do that. I would expect that if I am using the logged command, the serialization mapping should continue to work. It took quite a while trying to figure out why I was having to add BsonElement annotations after switching to using AppendStage with the command that was logged.

            Assignee:
            dmitry.lukyanov@mongodb.com Dmitry Lukyanov (Inactive)
            Reporter:
            rcollette@yahoo.com Richard Collette
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: