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

Inconsistent results using $regex and sort()

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major - P3 Major - P3
    • None
    • None
    • Querying
    • None
    • ALL

    Description

      Using sort() on a $regex query seems to inconsistently break the $regex query:

      Without sort:
      > db.goog0005_Australia_may.interviews.find({'ident': {$regex: /^11952449|.*/}})

      { "_id" : ObjectId("4df92666fba5224032000000"), "ident" : "11952449|34050" } { "_id" : ObjectId("4df92666fba5224032000001"), "ident" : "11952449|34050" }

      With sort:
      > db.goog0005_Australia_may.interviews.find({'ident': {$regex: /^11952449|.*/}}).sort(

      {'_id': -1}

      )

      { "_id" : ObjectId("4df92666fba522403200000a"), "ident" : "11948252|34050" } { "_id" : ObjectId("4df92666fba5224032000009"), "ident" : "11948208|34050" } { "_id" : ObjectId("4df92666fba5224032000008"), "ident" : "11947965|34050" } { "_id" : ObjectId("4df92666fba5224032000007"), "ident" : "11947861|34050" } { "_id" : ObjectId("4df92666fba5224032000006"), "ident" : "11947846|34050" } { "_id" : ObjectId("4df92666fba5224032000005"), "ident" : "11947723|34050" } { "_id" : ObjectId("4df92666fba5224032000004"), "ident" : "11944922|34050" } { "_id" : ObjectId("4df92666fba5224032000003"), "ident" : "11944870|34050" } { "_id" : ObjectId("4df92666fba5224032000002"), "ident" : "11943967|34050" } { "_id" : ObjectId("4df92666fba5224032000001"), "ident" : "11952449|34050" } { "_id" : ObjectId("4df92666fba5224032000000"), "ident" : "11952449|34050" }

      It gets weirder. Trying the same query a few seconds later (with sort()) returns the result set that was previously returned without sort():
      > db.goog0005_Australia_may.interviews.find({'ident': {$regex: /^11952449|.*/}}).sort(

      {'_id': -1}

      )

      { "_id" : ObjectId("4df92666fba5224032000001"), "ident" : "11952449|34050" } { "_id" : ObjectId("4df92666fba5224032000000"), "ident" : "11952449|34050" }

      Note: These examples are all from the mongo shell. The original report of this problem used pymongo examples to reproduce so it doesn't seem to be a shell problem.

      Attachments

        Activity

          People

            aaron Aaron Staple
            bernie@mongodb.com Bernie Hackett
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: