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

Logged Command property casing not serializer compatible

    XMLWordPrintable

    Details

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

      Description

      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.

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: