google-code-export / morphia

Automatically exported from code.google.com/p/morphia
1 stars 0 forks source link

Combined greaterThan and lessThanOrEq generates poor query #391

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Using Morphia 0.99, I have the following code:

  q.field("wordCount").greaterThanOrEq(1);
  q.field("wordCount").lessThanOrEq(2);

According to http://code.google.com/p/morphia/wiki/Query this should work, but 
it generates:

 { "wordCount" : { "$gte" : 1}} , { "wordCount" : { "$lte" : 2}} 

and the query parser ignores one of the bounds and I lose index efficiency. 
Shouldn't the generated query be:

 { "wordCount" : { "$gte" : 1, "$lte" : 2}} ?

Is there a way I can hardcode this into a Morphia Query object?

Original issue reported on code.google.com by nic%tran...@gtempaccount.com on 19 Mar 2012 at 7:31

GoogleCodeExporter commented 9 years ago
Sorry - I just tried the second way with explain, and I still get:

        "wordCount" : [
            [
                1,
                1.7976931348623157e+308
            ]
        ],

reported by indexBounds. Is this a Mongo bug? Or do I misunderstand how the 
index is used?

Original comment by nic%tran...@gtempaccount.com on 19 Mar 2012 at 7:41