JsonOutputMode.Shell should output NumberInt(12345) for int32 types

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Won't Fix
    • Priority: Major - P3
    • None
    • Affects Version/s: 2.11.0
    • Component/s: Json
    • None
    • Environment:
      Windows 10, C#
    • None
    • 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?
    • None
    • None
    • None
    • None
    • None
    • None

      I'm trying to convert a BsonDocument to a JSON string that MongoShell can correctly interpret. I'm not getting the expected results. Here's my sample code to reproduce the issue: 

      public static void Main()
      {
          var json = "{\"myinteger\" : 12345 }";
          var bsonDocument = BsonDocument.Parse(json);
          if (!bsonDocument["myinteger"].IsInt32)
              throw new ApplicationException("myInteger element is not an int32");
          var settings = new JsonWriterSettings { OutputMode = JsonOutputMode.Shell };
          var mainJson = bsonDocument.ToJson(settings);
      }

      This is just a very small part of the code that is trying to generate MongoShell commands to update a MongoDB database. What I get stored in mainJson is this: 

      { "myinteger" : 12345 }

       What I expected is this: 

      { "myinteger" : NumberInt(12345) }

      Notice that NumberInt is missing.

      This is a critical difference because MongoShell will interpret the first as a floating point number and store it as a floating point number when doing a $set, but will correctly interpret the second as an int32 and store it as an int32 when doing a $set.

      I'm using the latest official MongoDB C# NuGet driver, version 2.8.0. Is it possible I've found a bug in ToJson() or am I just missing something?

            Assignee:
            Boris Dogadov
            Reporter:
            Cody Gibson
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: