QueryTester's parser should not accept Extended JSON style $-prefixed escapes

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      The QueryTester has invented its own text-based format for representing BSON documents as text in a succinct, human-readable way. The QueryTester project explicitly chose not to use Extended JSON, primarily to increase readability but also because Extended JSON fails to ensure that any BSON document can be faithfully represented. Furthermore, Extended JSON is explicitly a way to represent BSON as JSON, whereas in the context of QueryTester a non-JSON text format is acceptable.

      I noticed that the QueryTester implementation, however, currently uses a parser which accepts Extended JSON-style $-prefixed escapes. Here's an example. The following invocation of mongotest passes:

      ./bazel-bin/install-mongotest/bin/mongotest -t extended_json.test --drop --load --mode compare
      

      The contents of the relevant test files are:

      $ cat basic.coll
      {_id: 1}
      
      {_id: NumberLong("42")}
      
      $ cat extended_json.test
      extended_json
      test
      basic.coll as c
      
      :results {find: "c", filter: {_id:{$eq: {$numberLong: "42"}}}}
      
      $ cat extended_json.results
      extended_json
      test
      basic.coll as c
      
      0
      :results {find: "c", filter: {_id:{$eq: {$numberLong: "42"}}}}
      [
      {"_id":42}
      ]
      

      In this example, {$numberLong: "42"} is interpreted as the number 42 (as a signed 64-bit integer). I would argue that the correct behavior is for this object to be interpreted literally. The query should match nothing because there are no documents whose _id is the nested document {$numberLong: "42"}.

      I noticed this while reviewing the changes for SERVER-98486, which is documenting the BSON Text Format used by QueryTester. I think it's important for there to be a clear conceptual distinction between Extended JSON and the BSON Text Format.

            Assignee:
            Unassigned
            Reporter:
            David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: