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

find_one with sort and PRIMARY_PREFERRED returning no output

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.0.1
    • Affects Version/s: 3.0
    • Component/s: None
    • Labels:
      None
    • Environment:
      pymongo==3.0.1-2-81549e

      This is a really strange one...

      When connecting through a mongos, I'm seeing an issue where find_one with PRIMARY_PREFERRED doesn't return any output.

      c = ...some_collection ...
      c.with_options(read_preference=ReadPreference.PRIMARY_PREFERRED)
      c.find_one({'symbol': symbol}, sort=[('version', pymongo.DESCENDING)])
      

      returns None. Whereas:

      c.find_one({'symbol': symbol})
      

      return an item.

      len(list(c.find({'symbol': symbol}))
      Out[76]: 25
      
      In [79]: [x for x in list(c.find({'symbol': symbol})) if x is None]
      Out[79]: []
      

      Note a normal find finds nothing too.

      In [84]: c = lib._versions.with_options(read_preference=ReadPreference.PRIMARY_PREFERRED)
      In [85]: len(list(c.find({'symbol': symbol}, sort=[('version', pymongo.DESCENDING)])))
      Out[85]: 0
      

      If I change the read-preference, it works!

      In [82]: c = lib._versions.with_options(read_preference=ReadPreference.PRIMARY)
      In [83]: len(list(c.find({'symbol': symbol}, sort=[('version', pymongo.DESCENDING)])))
      Out[83]: 25
      

            Assignee:
            bernie@mongodb.com Bernie Hackett
            Reporter:
            jblackburn James Blackburn
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: