Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-3028

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

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 4.0.1, 3.12.3
    • JSON

    Description

      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
      

      Attachments

        Activity

          People

            julius.park@mongodb.com Julius Park
            daniel.coupal@mongodb.com Daniel Coupal
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: