[SERVER-3269] Inconsistent results using $regex and sort() Created: 15/Jun/11  Updated: 30/Mar/12  Resolved: 20/Jun/11

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Bernie Hackett Assignee: Aaron Staple
Resolution: Duplicate Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Operating System: ALL
Participants:

 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.



 Comments   
Comment by Aaron Staple [ 20/Jun/11 ]

I filed SERVER-3298 to cover this.

Generated at Thu Feb 08 03:02:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.