Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-86945

$jsonSchema with $field in properties is not re-parseable

    • Query Optimization
    • Fully Compatible
    • v8.0, v7.3
    • 135

      The question is if it should be valid for $jsonSchema to have properties with $. Update: confirmed that this is a valid case.

      The error in BF-31616 is due to the fact that $jsonSchema directly parses into a match expression. If $jsonSchema has a property with $[name], the match expression that it is parsed to is not proper bson and is unable to be reparsed, causing errors in query stats (and possibly situations beyond query stats, either now or in the future).

      ex. Original Query:

      coll.find({ $jsonSchema: { properties: { $stdDevPop:
      { type: 'array' }
      } } }, { _id: 1 }).sort({ _id: 1 }).toArray()
      

       Parsed match expression:

      { $and: [ { $and: [ { $or: [ { $stdDevPop: { $not:
      { $exists: true }
      } }, { $and: [ { $stdDevPop:
      { $_internalSchemaType: [ 4 ] }
      } ] } ] } ] } ] }
      

      On the re-parse, having $stdDevPop as a field name is not allowed. 
      error:

      unknown top level operator: $stdDevPop. If you have a field name that starts with a '$' symbol, consider using $getField or $setField.

            Assignee:
            lynne.wang@mongodb.com Lynne Wang
            Reporter:
            erin.zhu@mongodb.com Erin Zhu
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: