$regex as a field name does not allow for non-string values

XMLWordPrintableJSON

    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Starting with MongoDB 5.0.4, db.serverStatus() adds counters for match operators.
      The entry for 'metrics.operatorCounters.match' looks like:

                "match": {
                  "$all": 0,
      ...
                  "$or": 4249,
                  "$regex": 21,
                  "$sampleRate": 0,
                  "$size": 0,
                  "$text": 0,
                  "$type": 7,
                  "$where": 0
                }
      

      The problem is with the "$regex" field that is rejected by the BSON library.

      Here is short program showing the failure.

      #!python
      
      # works
      regex_str_doc = """
      {
          "$regex": "10"
      }
      """
      
      # fails
      regex_int_doc = """
      {
          "$regex": 10
      }
      """
      
      import bson.json_util
      import pymongo
      
      o = bson.json_util.loads(regex_str_doc)     # works
      #o = bson.json_util.loads(regex_int_doc)     # fails
      

              Assignee:
              Julius Park (Inactive)
              Reporter:
              Daniel Coupal
              Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

                Created:
                Updated:
                Resolved: