[SERVER-13621] $geoWithin with backwards $box coordinates erroneously returns results Created: 17/Apr/14  Updated: 11/Jul/16  Resolved: 23/May/14

Status: Closed
Project: Core Server
Component/s: Geo
Affects Version/s: 2.6.0
Fix Version/s: 2.7.1, 2.7.7

Type: Bug Priority: Major - P3
Reporter: Eriol Gjergji Assignee: Siyuan Zhou
Resolution: Done Votes: 0
Labels: 2d, cap-ticket-needed, geowithin
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File server13621_repro.js    
Issue Links:
Tested
Participants:

 Description   

// Setup
> t = db.t
> t.drop()
> t.ensureIndex({loc: "2d"})
> t.save({loc: [0, 0]})
 
// The doc is in the box, but the box coordinates are backwards. Should return zero results.
> t.find({loc: {$geoWithin: {$box: [ [ 5, 5 ], [-5, -5] ] }}})
{ "_id" : ObjectId("534ffa11a7931e19d3eb0027"), "loc" : [ 0, 0 ] } // Got a result, but we shouldn't have.
 
// If we hint to use a non-2d index, then we correctly return zero results:
> t.find({loc: {$geoWithin: {$box: [ [ 5, 5 ], [-5, -5] ] }}}).hint({_id: 1})
 
// Everything works as expected if we flip the $box coordinates:
> t.find({loc: {$geoWithin: {$box: [ [ -5, -5 ], [5, 5] ] }}})
{ "_id" : ObjectId("534ffa11a7931e19d3eb0027"), "loc" : [ 0, 0 ] }
> t.find({loc: {$geoWithin: {$box: [ [ -5, -5 ], [5, 5] ] }}}).hint({_id: 1})
{ "_id" : ObjectId("534ffa11a7931e19d3eb0027"), "loc" : [ 0, 0 ] }

Original Description

if I exec this query:

db.Listings.find( { location : { $geoWithin : { $box :
       [ [ -80.84271171946818, 26.723380302236098 ],
         [ -82.32517937083537, 26.21012478434639 ] ] } } } ).explain()

I get "n" : 49097 so there are around 50K records

(this is a cluster with 2 shards and shard key is the hashed _id )

but when I put the .sort({_id: -1}) the result is "n": 0 - even if I change the sort to another field (indexed field) I get the same result

MongoDB 2.6.0 (all machines mogos, conf boxes and shards)



 Comments   
Comment by Githook User [ 18/Sep/14 ]

Author:

{u'username': u'visualzhou', u'name': u'Siyuan Zhou', u'email': u'siyuan.zhou@mongodb.com'}

Message: SERVER-13621 Add JS tests for backwards box coordinates
Branch: master
https://github.com/mongodb/mongo/commit/035b928655398f6884a1404d7876b6cc1bd47e54

Comment by Greg Studer [ 23/May/14 ]

This issue was fixed during some refactoring for SERVER-5800:

https://jira.mongodb.org/browse/SERVER-5800?focusedCommentId=590578&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-590578

Comment by Greg Studer [ 01/May/14 ]

> what I mean is if 2dsphere is faster then 2d
They use a similar approach but with different hashed box sizes, so it'll depend on the queries themselves. 2dsphere also has some spherical math overhead, 2d currently performs worse for $geoNear in some cases.

> its same on the sphere and on 2d
Not true - the edges of your query box are different if you use a $box vs GeoJSON Polygon ($box isn't accelerated by 2dsphere indexes for this reason). If you're querying and displaying the results on a flat map, the results returned will appear to be bounded by curved edges if using GeoJSON. (This won't really be noticeable though unless your boxes are hundreds of miles long.)

Comment by Eriol Gjergji [ 17/Apr/14 ]

The use case is about showing some clusters and markers on google map, and I think in this case a coordinate is a coordinate, its same on the sphere and on 2d, what I mean is if 2dsphere is faster then 2d

Comment by hari.khalsa@10gen.com [ 17/Apr/14 ]

$box queries are only for a flat plane. 2dsphere indices are for indexing geometry on a sphere. Which one you should use depends on your use case.

Comment by Eriol Gjergji [ 17/Apr/14 ]

Ok great now is working properly.. is there any better way for getting results in this specific case, does 2dsphere works better?
Thanks.

Comment by David Storch [ 17/Apr/14 ]

Hi Eriol,

As specified in the documentation (see http://docs.mongodb.org/manual/reference/operator/query/box/), the coordinates for $box must be specified with the lower-left coordinate first and the upper-right coordinates second. In the query

db.Listings.find( { location : { $geoWithin : { $box :
       [ [ -80.84271171946818, 26.723380302236098 ],
         [ -82.32517937083537, 26.21012478434639 ] ] } } } );

this order is inverted. The bug is therefore not that zero results are returned---in fact, zero results is always the expected result for this query! Rather, the bug is that the query plan using the "2d" index returns results when it should not. I'm going to update the description and title of this ticket accordingly. Thanks for very much for your help.

Comment by Eriol Gjergji [ 17/Apr/14 ]

Thank you

Comment by David Storch [ 17/Apr/14 ]

Hi Eriol, thanks for the additional info. I have been able to reproduce the issue locally using the attached script ("server13621_repro.js"). I will continue to investigate in order to diagnose the root cause.

Comment by Eriol Gjergji [ 17/Apr/14 ]

printjson(db.Listings.stats())

{
"sharded" : true,
"systemFlags" : 0,
"userFlags" : 1,
"ns" : "mls.Listings",
"count" : 133782,
"numExtents" : 30,
"size" : 715325216,
"storageSize" : 889954304,
"totalIndexSize" : 116622464,
"indexSizes" :

{ "_id_" : 6974128, "_id_hashed" : 6287344, "acres_1" : 4979184, "bathsTotal_1" : 3491152, "bedroomsTotal_1" : 3532032, "boardName_1" : 3842720, "city_1" : 4750256, "createdDate_1" : 4267872, "currentPrice_1" : 5764080, "daysOnMarket_1" : 5674144, "fullAddress_1" : 6867840, "garageTotal_1" : 3916304, "interiorFeatures_1" : 14095424, "lastUpdatedDateTime_1" : 3572912, "listingType_1" : 2869776, "livingArea_1" : 5404336, "location_2d" : 3262224, "mlsNumber_1" : 4079824, "mlsNumber_1_unique_" : 4194288, "propertyTypeQuery_1" : 2943360, "state_1" : 2738960, "status_1" : 3785488, "yearBuilt_1" : 4398688, "zip_1" : 4930128 }

,
"avgObjSize" : 5346.946644541119,
"nindexes" : 24,
"nchunks" : 20,
"shards" : {
"shard0000" : {
"ns" : "mls.Listings",
"count" : 65116,
"size" : 347826752,
"avgObjSize" : 5341,
"storageSize" : 429092864,
"numExtents" : 16,
"nindexes" : 24,
"lastExtentSize" : 114012160,
"paddingFactor" : 1,
"systemFlags" : 0,
"userFlags" : 1,
"totalIndexSize" : 57346464,
"indexSizes" :

{ "_id_" : 3810016, "_id_hashed" : 3098704, "mlsNumber_1_unique_" : 2068528, "listingType_1" : 1398096, "propertyTypeQuery_1" : 1438976, "lastUpdatedDateTime_1" : 1749664, "currentPrice_1" : 2771664, "daysOnMarket_1" : 2755312, "garageTotal_1" : 1913184, "yearBuilt_1" : 2133936, "acres_1" : 2436448, "livingArea_1" : 2632672, "interiorFeatures_1" : 6835136, "bedroomsTotal_1" : 1708784, "bathsTotal_1" : 1708784, "createdDate_1" : 2125760, "status_1" : 1864128, "fullAddress_1" : 3352160, "city_1" : 2330160, "state_1" : 1332688, "zip_1" : 2395568, "boardName_1" : 1880480, "mlsNumber_1" : 2011296, "location_2d" : 1594320 }

,
"ok" : 1
},
"shard0001" : {
"ns" : "mls.Listings",
"count" : 68666,
"size" : 367498464,
"avgObjSize" : 5351,
"storageSize" : 460861440,
"numExtents" : 14,
"nindexes" : 24,
"lastExtentSize" : 124993536,
"paddingFactor" : 1.0080000000000002,
"systemFlags" : 0,
"userFlags" : 1,
"totalIndexSize" : 59276000,
"indexSizes" :

{ "_id_" : 3164112, "_id_hashed" : 3188640, "mlsNumber_1_unique_" : 2125760, "listingType_1" : 1471680, "propertyTypeQuery_1" : 1504384, "lastUpdatedDateTime_1" : 1823248, "currentPrice_1" : 2992416, "daysOnMarket_1" : 2918832, "garageTotal_1" : 2003120, "yearBuilt_1" : 2264752, "acres_1" : 2542736, "livingArea_1" : 2771664, "interiorFeatures_1" : 7260288, "bedroomsTotal_1" : 1823248, "bathsTotal_1" : 1782368, "createdDate_1" : 2142112, "status_1" : 1921360, "fullAddress_1" : 3515680, "city_1" : 2420096, "state_1" : 1406272, "zip_1" : 2534560, "boardName_1" : 1962240, "mlsNumber_1" : 2068528, "location_2d" : 1667904 }

,
"ok" : 1
}
},
"ok" : 1
}

printjson(db.Listings.getIndexes())

[
{
"v" : 1,
"key" :

{ "_id" : 1 }

,
"name" : "id",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "_id" : "hashed" }

,
"name" : "_id_hashed",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "mlsNumber" : 1, "unique" : true }

,
"name" : "mlsNumber_1_unique_",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "listingType" : 1 }

,
"name" : "listingType_1",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "propertyTypeQuery" : 1 }

,
"name" : "propertyTypeQuery_1",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "lastUpdatedDateTime" : 1 }

,
"name" : "lastUpdatedDateTime_1",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "currentPrice" : 1 }

,
"name" : "currentPrice_1",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "daysOnMarket" : 1 }

,
"name" : "daysOnMarket_1",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "garageTotal" : 1 }

,
"name" : "garageTotal_1",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "yearBuilt" : 1 }

,
"name" : "yearBuilt_1",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "acres" : 1 }

,
"name" : "acres_1",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "livingArea" : 1 }

,
"name" : "livingArea_1",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "interiorFeatures" : 1 }

,
"name" : "interiorFeatures_1",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "bedroomsTotal" : 1 }

,
"name" : "bedroomsTotal_1",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "bathsTotal" : 1 }

,
"name" : "bathsTotal_1",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "createdDate" : 1 }

,
"name" : "createdDate_1",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "status" : 1 }

,
"name" : "status_1",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "fullAddress" : 1 }

,
"name" : "fullAddress_1",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "city" : 1 }

,
"name" : "city_1",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "state" : 1 }

,
"name" : "state_1",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "zip" : 1 }

,
"name" : "zip_1",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "boardName" : 1 }

,
"name" : "boardName_1",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "mlsNumber" : 1 }

,
"name" : "mlsNumber_1",
"ns" : "mls.Listings"
},
{
"v" : 1,
"key" :

{ "location" : "2d" }

,
"name" : "location_2d",
"ns" : "mls.Listings"
}
]

printjson(db.Listings.find( { location : { $geoWithin :

{ $box : [ [ -80.84271171946818,26.723380302236098 ],[ -82.32517937083537,26.21012478434639 ] ] }

} },

{location: 1}

).limit(3).toArray())

[

{ "_id" : ObjectId("533df609e4b0e7fd59e8b05b"), "location" : [ -81.5762710571289, 26.4752197265625 ] }

,

{ "_id" : ObjectId("52ea82c0bedd662c6f0a84de"), "location" : [ -81.5733337402344, 26.4694728851318 ] }

,

{ "_id" : ObjectId("52ea81a4bedd662c6f0a6c0d"), "location" : [ -81.5765151977539, 26.5299777984619 ] }

]

And the sharding status:

sharding version: {
"_id" : 1,
"version" : 4,
"minCompatibleVersion" : 4,
"currentVersion" : 5,
"clusterId" : ObjectId("534e46c4f0372c2ac002c2f2")
}
shards:

{ "_id" : "shard0000", "host" : "10.0.0.100:27017" } { "_id" : "shard0001", "host" : "10.0.0.99:27017" }

databases:

{ "_id" : "admin", "partitioned" : false, "primary" : "config" } { "_id" : "test", "partitioned" : false, "primary" : "shard0000" } { "_id" : "mls", "partitioned" : true, "primary" : "shard0000" }

mls.Listings
shard key:

{ "_id" : "hashed" }

chunks:
shard0001 10
shard0000 10
{ "_id" :

{ $minKey : 1 }

} -->>

{ "_id" : NumberLong("-8083792868103947337") }

on : shard0001 Timestamp(4000, 0)

{ "_id" : NumberLong("-8083792868103947337") }

-->>

{ "_id" : NumberLong("-6930339516001539937") }

on : shard0001 Timestamp(5000, 0)

{ "_id" : NumberLong("-6930339516001539937") }

-->>

{ "_id" : NumberLong("-5769105298234587493") }

on : shard0000 Timestamp(5000, 1)

{ "_id" : NumberLong("-5769105298234587493") }

-->>

{ "_id" : NumberLong("-4611686018427387902") }

on : shard0000 Timestamp(3000, 5)

{ "_id" : NumberLong("-4611686018427387902") }

-->>

{ "_id" : NumberLong("-3764275168950234232") }

on : shard0000 Timestamp(4000, 4)

{ "_id" : NumberLong("-3764275168950234232") }

-->>

{ "_id" : NumberLong("-3176496131987439059") }

on : shard0000 Timestamp(5000, 4)

{ "_id" : NumberLong("-3176496131987439059") }

-->>

{ "_id" : NumberLong("-2450726271619610265") }

on : shard0000 Timestamp(5000, 5)

{ "_id" : NumberLong("-2450726271619610265") }

-->>

{ "_id" : NumberLong("-1903153479925541869") }

on : shard0000 Timestamp(5000, 8)

{ "_id" : NumberLong("-1903153479925541869") }

-->>

{ "_id" : NumberLong("-1240991362367586446") }

on : shard0000 Timestamp(5000, 9)

{ "_id" : NumberLong("-1240991362367586446") }

-->>

{ "_id" : NumberLong(0) }

on : shard0000 Timestamp(3000, 3)

{ "_id" : NumberLong(0) }

-->>

{ "_id" : NumberLong("942952600555559180") }

on : shard0000 Timestamp(4000, 2)

{ "_id" : NumberLong("942952600555559180") }

-->>

{ "_id" : NumberLong("2053983560128391446") }

on : shard0000 Timestamp(4000, 3)

{ "_id" : NumberLong("2053983560128391446") }

-->>

{ "_id" : NumberLong("3166399862752592245") }

on : shard0001 Timestamp(3000, 1)

{ "_id" : NumberLong("3166399862752592245") }

-->>

{ "_id" : NumberLong("3756873253059263436") }

on : shard0001 Timestamp(5000, 2)

{ "_id" : NumberLong("3756873253059263436") }

-->>

{ "_id" : NumberLong("4611686018427387902") }

on : shard0001 Timestamp(5000, 3)

{ "_id" : NumberLong("4611686018427387902") }

-->>

{ "_id" : NumberLong("5737595591553482218") }

on : shard0001 Timestamp(2000, 16)

{ "_id" : NumberLong("5737595591553482218") }

-->>

{ "_id" : NumberLong("6884369708377834871") }

on : shard0001 Timestamp(2000, 17)

{ "_id" : NumberLong("6884369708377834871") }

-->>

{ "_id" : NumberLong("8023763089855937351") }

on : shard0001 Timestamp(3000, 6)

{ "_id" : NumberLong("8023763089855937351") }

-->>

{ "_id" : NumberLong("8586656359143825175") }

on : shard0001 Timestamp(5000, 6)

{ "_id" : NumberLong("8586656359143825175") }

-->> { "_id" :

{ $maxKey : 1 }

} on : shard0001 Timestamp(5000, 7)

Comment by Scott Hernandez (Inactive) [ 17/Apr/14 ]

Can you please post the following so we can try to reproduce this?

printjson(db.Listings.stats())
printjson(db.Listings.getIndexes())
printjson(db.Listings.find( { location : { $geoWithin : { $box : [ [ -80.84271171946818,26.723380302236098 ],[ -82.32517937083537,26.21012478434639 ] ] } } } ).limit(3).toArray())
printjson(sh.status())

Can you also please post the full queries you are using for those explains, including the explain output (which you included above)?

Comment by Eriol Gjergji [ 17/Apr/14 ]

location index is a "2d" index, if I do it "2dsphere" it doesn't work at all - collection is around 100K records, the data returned without the sort is about 50K
but when I put the sort it doesn't return any records, and doesn't trigger any errors.

Not sure what the deal is, but when I run the same query on single box (not on shard cluster) its working properly.

Explain response from query without sort:

/* 0 */
{
    "clusteredType" : "ParallelSort",
    "shards" : {
        "10.0.0.100:27017" : [ 
            {
                "cursor" : "GeoBrowse-box",
                "isMultiKey" : false,
                "n" : 23915,
                "nscannedObjects" : 23915,
                "nscanned" : 23915,
                "nscannedObjectsAllPlans" : 23915,
                "nscannedAllPlans" : 23915,
                "scanAndOrder" : false,
                "indexOnly" : false,
                "nYields" : 186,
                "nChunkSkips" : 0,
                "millis" : 129,
                "indexBounds" : {
                    "location" : [ 
                        [ 
                            [ 
                                -82.96875, 
                                25.3125
                            ], 
                            [ 
                                -81.5625, 
                                26.71875
                            ]
                        ], 
                        [ 
                            [ 
                                -81.9140625, 
                                26.71875
                            ], 
                            [ 
                                -81.5625, 
                                27.0703125
                            ]
                        ], 
                        [ 
                            [ 
                                -82.265625, 
                                26.71875
                            ], 
                            [ 
                                -81.9140625, 
                                27.0703125
                            ]
                        ], 
                        [ 
                            [ 
                                -82.6171875, 
                                26.71875
                            ], 
                            [ 
                                -82.265625, 
                                27.0703125
                            ]
                        ], 
                        [ 
                            [ 
                                -80.859375, 
                                26.3671875
                            ], 
                            [ 
                                -80.5078125, 
                                26.71875
                            ]
                        ], 
                        [ 
                            [ 
                                -80.859375, 
                                26.015625
                            ], 
                            [ 
                                -80.5078125, 
                                26.3671875
                            ]
                        ], 
                        [ 
                            [ 
                                -81.5625, 
                                26.015625
                            ], 
                            [ 
                                -80.859375, 
                                26.71875
                            ]
                        ], 
                        [ 
                            [ 
                                -80.859375, 
                                26.71875
                            ], 
                            [ 
                                -80.5078125, 
                                27.0703125
                            ]
                        ], 
                        [ 
                            [ 
                                -81.2109375, 
                                26.71875
                            ], 
                            [ 
                                -80.859375, 
                                27.0703125
                            ]
                        ], 
                        [ 
                            [ 
                                -81.5625, 
                                26.71875
                            ], 
                            [ 
                                -81.2109375, 
                                27.0703125
                            ]
                        ]
                    ]
                },
                "allPlans" : [ 
                    {
                        "cursor" : "GeoBrowse-box",
                        "isMultiKey" : false,
                        "n" : 23915,
                        "nscannedObjects" : 23915,
                        "nscanned" : 23915,
                        "scanAndOrder" : false,
                        "indexOnly" : false,
                        "nChunkSkips" : 0,
                        "indexBounds" : {
                            "location" : [ 
                                [ 
                                    [ 
                                        -82.96875, 
                                        25.3125
                                    ], 
                                    [ 
                                        -81.5625, 
                                        26.71875
                                    ]
                                ], 
                                [ 
                                    [ 
                                        -81.9140625, 
                                        26.71875
                                    ], 
                                    [ 
                                        -81.5625, 
                                        27.0703125
                                    ]
                                ], 
                                [ 
                                    [ 
                                        -82.265625, 
                                        26.71875
                                    ], 
                                    [ 
                                        -81.9140625, 
                                        27.0703125
                                    ]
                                ], 
                                [ 
                                    [ 
                                        -82.6171875, 
                                        26.71875
                                    ], 
                                    [ 
                                        -82.265625, 
                                        27.0703125
                                    ]
                                ], 
                                [ 
                                    [ 
                                        -80.859375, 
                                        26.3671875
                                    ], 
                                    [ 
                                        -80.5078125, 
                                        26.71875
                                    ]
                                ], 
                                [ 
                                    [ 
                                        -80.859375, 
                                        26.015625
                                    ], 
                                    [ 
                                        -80.5078125, 
                                        26.3671875
                                    ]
                                ], 
                                [ 
                                    [ 
                                        -81.5625, 
                                        26.015625
                                    ], 
                                    [ 
                                        -80.859375, 
                                        26.71875
                                    ]
                                ], 
                                [ 
                                    [ 
                                        -80.859375, 
                                        26.71875
                                    ], 
                                    [ 
                                        -80.5078125, 
                                        27.0703125
                                    ]
                                ], 
                                [ 
                                    [ 
                                        -81.2109375, 
                                        26.71875
                                    ], 
                                    [ 
                                        -80.859375, 
                                        27.0703125
                                    ]
                                ], 
                                [ 
                                    [ 
                                        -81.5625, 
                                        26.71875
                                    ], 
                                    [ 
                                        -81.2109375, 
                                        27.0703125
                                    ]
                                ]
                            ]
                        }
                    }
                ],
                "server" : "ip-10-0-0-100:27017",
                "filterSet" : false,
                "stats" : {
                    "type" : "KEEP_MUTATIONS",
                    "works" : 23917,
                    "yields" : 186,
                    "unyields" : 186,
                    "invalidates" : 0,
                    "advanced" : 23915,
                    "needTime" : 1,
                    "needFetch" : 0,
                    "isEOF" : 1,
                    "children" : [ 
                        {
                            "type" : "SHARDING_FILTER",
                            "works" : 23917,
                            "yields" : 186,
                            "unyields" : 186,
                            "invalidates" : 0,
                            "advanced" : 23915,
                            "needTime" : 1,
                            "needFetch" : 0,
                            "isEOF" : 1,
                            "chunkSkips" : 0,
                            "children" : [ 
                                {
                                    "type" : "FETCH",
                                    "works" : 23917,
                                    "yields" : 186,
                                    "unyields" : 186,
                                    "invalidates" : 0,
                                    "advanced" : 23915,
                                    "needTime" : 1,
                                    "needFetch" : 0,
                                    "isEOF" : 1,
                                    "alreadyHasObj" : 23915,
                                    "forcedFetches" : 0,
                                    "matchTested" : 0,
                                    "children" : [ 
                                        {
                                            "type" : "GEO_2D",
                                            "works" : 23915,
                                            "yields" : 0,
                                            "unyields" : 0,
                                            "invalidates" : 0,
                                            "advanced" : 23915,
                                            "needTime" : 0,
                                            "needFetch" : 0,
                                            "isEOF" : 1,
                                            "geometryType" : "box",
                                            "field" : "location",
                                            "boundsVerbose" : [ 
                                                "(-82.9688,25.3125) -->> (-81.5625,26.7188)", 
                                                "(-81.9141,26.7188) -->> (-81.5625,27.0703)", 
                                                "(-82.2656,26.7188) -->> (-81.9141,27.0703)", 
                                                "(-82.6172,26.7188) -->> (-82.2656,27.0703)", 
                                                "(-80.8594,26.3672) -->> (-80.5078,26.7188)", 
                                                "(-80.8594,26.0156) -->> (-80.5078,26.3672)", 
                                                "(-81.5625,26.0156) -->> (-80.8594,26.7188)", 
                                                "(-80.8594,26.7188) -->> (-80.5078,27.0703)", 
                                                "(-81.2109,26.7188) -->> (-80.8594,27.0703)", 
                                                "(-81.5625,26.7188) -->> (-81.2109,27.0703)"
                                            ],
                                            "children" : []
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            }
        ],
        "10.0.0.99:27017" : [ 
            {
                "cursor" : "GeoBrowse-box",
                "isMultiKey" : false,
                "n" : 25222,
                "nscannedObjects" : 25222,
                "nscanned" : 25222,
                "nscannedObjectsAllPlans" : 25222,
                "nscannedAllPlans" : 25222,
                "scanAndOrder" : false,
                "indexOnly" : false,
                "nYields" : 197,
                "nChunkSkips" : 0,
                "millis" : 140,
                "indexBounds" : {
                    "location" : [ 
                        [ 
                            [ 
                                -82.96875, 
                                25.3125
                            ], 
                            [ 
                                -81.5625, 
                                26.71875
                            ]
                        ], 
                        [ 
                            [ 
                                -81.9140625, 
                                26.71875
                            ], 
                            [ 
                                -81.5625, 
                                27.0703125
                            ]
                        ], 
                        [ 
                            [ 
                                -82.265625, 
                                26.71875
                            ], 
                            [ 
                                -81.9140625, 
                                27.0703125
                            ]
                        ], 
                        [ 
                            [ 
                                -82.6171875, 
                                26.71875
                            ], 
                            [ 
                                -82.265625, 
                                27.0703125
                            ]
                        ], 
                        [ 
                            [ 
                                -80.859375, 
                                26.3671875
                            ], 
                            [ 
                                -80.5078125, 
                                26.71875
                            ]
                        ], 
                        [ 
                            [ 
                                -80.859375, 
                                26.015625
                            ], 
                            [ 
                                -80.5078125, 
                                26.3671875
                            ]
                        ], 
                        [ 
                            [ 
                                -81.5625, 
                                26.015625
                            ], 
                            [ 
                                -80.859375, 
                                26.71875
                            ]
                        ], 
                        [ 
                            [ 
                                -80.859375, 
                                26.71875
                            ], 
                            [ 
                                -80.5078125, 
                                27.0703125
                            ]
                        ], 
                        [ 
                            [ 
                                -81.2109375, 
                                26.71875
                            ], 
                            [ 
                                -80.859375, 
                                27.0703125
                            ]
                        ], 
                        [ 
                            [ 
                                -81.5625, 
                                26.71875
                            ], 
                            [ 
                                -81.2109375, 
                                27.0703125
                            ]
                        ]
                    ]
                },
                "allPlans" : [ 
                    {
                        "cursor" : "GeoBrowse-box",
                        "isMultiKey" : false,
                        "n" : 25222,
                        "nscannedObjects" : 25222,
                        "nscanned" : 25222,
                        "scanAndOrder" : false,
                        "indexOnly" : false,
                        "nChunkSkips" : 0,
                        "indexBounds" : {
                            "location" : [ 
                                [ 
                                    [ 
                                        -82.96875, 
                                        25.3125
                                    ], 
                                    [ 
                                        -81.5625, 
                                        26.71875
                                    ]
                                ], 
                                [ 
                                    [ 
                                        -81.9140625, 
                                        26.71875
                                    ], 
                                    [ 
                                        -81.5625, 
                                        27.0703125
                                    ]
                                ], 
                                [ 
                                    [ 
                                        -82.265625, 
                                        26.71875
                                    ], 
                                    [ 
                                        -81.9140625, 
                                        27.0703125
                                    ]
                                ], 
                                [ 
                                    [ 
                                        -82.6171875, 
                                        26.71875
                                    ], 
                                    [ 
                                        -82.265625, 
                                        27.0703125
                                    ]
                                ], 
                                [ 
                                    [ 
                                        -80.859375, 
                                        26.3671875
                                    ], 
                                    [ 
                                        -80.5078125, 
                                        26.71875
                                    ]
                                ], 
                                [ 
                                    [ 
                                        -80.859375, 
                                        26.015625
                                    ], 
                                    [ 
                                        -80.5078125, 
                                        26.3671875
                                    ]
                                ], 
                                [ 
                                    [ 
                                        -81.5625, 
                                        26.015625
                                    ], 
                                    [ 
                                        -80.859375, 
                                        26.71875
                                    ]
                                ], 
                                [ 
                                    [ 
                                        -80.859375, 
                                        26.71875
                                    ], 
                                    [ 
                                        -80.5078125, 
                                        27.0703125
                                    ]
                                ], 
                                [ 
                                    [ 
                                        -81.2109375, 
                                        26.71875
                                    ], 
                                    [ 
                                        -80.859375, 
                                        27.0703125
                                    ]
                                ], 
                                [ 
                                    [ 
                                        -81.5625, 
                                        26.71875
                                    ], 
                                    [ 
                                        -81.2109375, 
                                        27.0703125
                                    ]
                                ]
                            ]
                        }
                    }
                ],
                "server" : "ip-10-0-0-99:27017",
                "filterSet" : false,
                "stats" : {
                    "type" : "KEEP_MUTATIONS",
                    "works" : 25224,
                    "yields" : 197,
                    "unyields" : 197,
                    "invalidates" : 0,
                    "advanced" : 25222,
                    "needTime" : 1,
                    "needFetch" : 0,
                    "isEOF" : 1,
                    "children" : [ 
                        {
                            "type" : "SHARDING_FILTER",
                            "works" : 25224,
                            "yields" : 197,
                            "unyields" : 197,
                            "invalidates" : 0,
                            "advanced" : 25222,
                            "needTime" : 1,
                            "needFetch" : 0,
                            "isEOF" : 1,
                            "chunkSkips" : 0,
                            "children" : [ 
                                {
                                    "type" : "FETCH",
                                    "works" : 25224,
                                    "yields" : 197,
                                    "unyields" : 197,
                                    "invalidates" : 0,
                                    "advanced" : 25222,
                                    "needTime" : 1,
                                    "needFetch" : 0,
                                    "isEOF" : 1,
                                    "alreadyHasObj" : 25222,
                                    "forcedFetches" : 0,
                                    "matchTested" : 0,
                                    "children" : [ 
                                        {
                                            "type" : "GEO_2D",
                                            "works" : 25222,
                                            "yields" : 0,
                                            "unyields" : 0,
                                            "invalidates" : 0,
                                            "advanced" : 25222,
                                            "needTime" : 0,
                                            "needFetch" : 0,
                                            "isEOF" : 1,
                                            "geometryType" : "box",
                                            "field" : "location",
                                            "boundsVerbose" : [ 
                                                "(-82.9688,25.3125) -->> (-81.5625,26.7188)", 
                                                "(-81.9141,26.7188) -->> (-81.5625,27.0703)", 
                                                "(-82.2656,26.7188) -->> (-81.9141,27.0703)", 
                                                "(-82.6172,26.7188) -->> (-82.2656,27.0703)", 
                                                "(-80.8594,26.3672) -->> (-80.5078,26.7188)", 
                                                "(-80.8594,26.0156) -->> (-80.5078,26.3672)", 
                                                "(-81.5625,26.0156) -->> (-80.8594,26.7188)", 
                                                "(-80.8594,26.7188) -->> (-80.5078,27.0703)", 
                                                "(-81.2109,26.7188) -->> (-80.8594,27.0703)", 
                                                "(-81.5625,26.7188) -->> (-81.2109,27.0703)"
                                            ],
                                            "children" : []
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            }
        ]
    },
    "cursor" : "GeoBrowse-box",
    "n" : 49137,
    "nChunkSkips" : 0,
    "nYields" : 383,
    "nscanned" : 49137,
    "nscannedAllPlans" : 49137,
    "nscannedObjects" : 49137,
    "nscannedObjectsAllPlans" : 49137,
    "millisShardTotal" : 269,
    "millisShardAvg" : 134,
    "numQueries" : 2,
    "numShards" : 2,
    "millis" : 141
}

Explain response from query with .sort({_id:-1})

/* 0 */
{
    "clusteredType" : "ParallelSort",
    "shards" : {
        "10.0.0.100:27017" : [ 
            {
                "cursor" : "BtreeCursor _id_ reverse",
                "isMultiKey" : false,
                "n" : 0,
                "nscannedObjects" : 64874,
                "nscanned" : 64874,
                "nscannedObjectsAllPlans" : 74428,
                "nscannedAllPlans" : 74428,
                "scanAndOrder" : false,
                "indexOnly" : false,
                "nYields" : 580,
                "nChunkSkips" : 0,
                "millis" : 427,
                "indexBounds" : {
                    "_id" : [ 
                        [ 
                            {
                                "$maxElement" : 1
                            }, 
                            {
                                "$minElement" : 1
                            }
                        ]
                    ]
                },
                "allPlans" : [ 
                    {
                        "cursor" : "BtreeCursor _id_ reverse",
                        "isMultiKey" : false,
                        "n" : 0,
                        "nscannedObjects" : 64874,
                        "nscanned" : 64874,
                        "scanAndOrder" : false,
                        "indexOnly" : false,
                        "nChunkSkips" : 0,
                        "indexBounds" : {
                            "_id" : [ 
                                [ 
                                    {
                                        "$maxElement" : 1
                                    }, 
                                    {
                                        "$minElement" : 1
                                    }
                                ]
                            ]
                        }
                    }, 
                    {
                        "cursor" : "GeoBrowse-box",
                        "isMultiKey" : false,
                        "n" : 0,
                        "nscannedObjects" : 9554,
                        "nscanned" : 9554,
                        "scanAndOrder" : true,
                        "indexOnly" : false,
                        "nChunkSkips" : 0,
                        "indexBounds" : {
                            "location" : []
                        }
                    }
                ],
                "server" : "ip-10-0-0-100:27017",
                "filterSet" : false,
                "stats" : {
                    "type" : "SHARDING_FILTER",
                    "works" : 64875,
                    "yields" : 580,
                    "unyields" : 580,
                    "invalidates" : 0,
                    "advanced" : 0,
                    "needTime" : 64874,
                    "needFetch" : 0,
                    "isEOF" : 1,
                    "chunkSkips" : 0,
                    "children" : [ 
                        {
                            "type" : "FETCH",
                            "works" : 64874,
                            "yields" : 580,
                            "unyields" : 580,
                            "invalidates" : 0,
                            "advanced" : 0,
                            "needTime" : 64874,
                            "needFetch" : 0,
                            "isEOF" : 1,
                            "alreadyHasObj" : 0,
                            "forcedFetches" : 0,
                            "matchTested" : 0,
                            "children" : [ 
                                {
                                    "type" : "IXSCAN",
                                    "works" : 64874,
                                    "yields" : 580,
                                    "unyields" : 580,
                                    "invalidates" : 0,
                                    "advanced" : 64874,
                                    "needTime" : 0,
                                    "needFetch" : 0,
                                    "isEOF" : 1,
                                    "keyPattern" : "{ _id: 1 }",
                                    "boundsVerbose" : "field #0['_id']: [MaxKey, MinKey]",
                                    "isMultiKey" : 0,
                                    "yieldMovedCursor" : 0,
                                    "dupsTested" : 0,
                                    "dupsDropped" : 0,
                                    "seenInvalidated" : 0,
                                    "matchTested" : 0,
                                    "keysExamined" : 64874,
                                    "children" : []
                                }
                            ]
                        }
                    ]
                }
            }
        ],
        "10.0.0.99:27017" : [ 
            {
                "cursor" : "BtreeCursor _id_ reverse",
                "isMultiKey" : false,
                "n" : 0,
                "nscannedObjects" : 68421,
                "nscanned" : 68421,
                "nscannedObjectsAllPlans" : 78033,
                "nscannedAllPlans" : 78033,
                "scanAndOrder" : false,
                "indexOnly" : false,
                "nYields" : 609,
                "nChunkSkips" : 0,
                "millis" : 417,
                "indexBounds" : {
                    "_id" : [ 
                        [ 
                            {
                                "$maxElement" : 1
                            }, 
                            {
                                "$minElement" : 1
                            }
                        ]
                    ]
                },
                "allPlans" : [ 
                    {
                        "cursor" : "BtreeCursor _id_ reverse",
                        "isMultiKey" : false,
                        "n" : 0,
                        "nscannedObjects" : 68421,
                        "nscanned" : 68421,
                        "scanAndOrder" : false,
                        "indexOnly" : false,
                        "nChunkSkips" : 0,
                        "indexBounds" : {
                            "_id" : [ 
                                [ 
                                    {
                                        "$maxElement" : 1
                                    }, 
                                    {
                                        "$minElement" : 1
                                    }
                                ]
                            ]
                        }
                    }, 
                    {
                        "cursor" : "GeoBrowse-box",
                        "isMultiKey" : false,
                        "n" : 0,
                        "nscannedObjects" : 9612,
                        "nscanned" : 9612,
                        "scanAndOrder" : true,
                        "indexOnly" : false,
                        "nChunkSkips" : 0,
                        "indexBounds" : {
                            "location" : []
                        }
                    }
                ],
                "server" : "ip-10-0-0-99:27017",
                "filterSet" : false,
                "stats" : {
                    "type" : "SHARDING_FILTER",
                    "works" : 68422,
                    "yields" : 609,
                    "unyields" : 609,
                    "invalidates" : 0,
                    "advanced" : 0,
                    "needTime" : 68421,
                    "needFetch" : 0,
                    "isEOF" : 1,
                    "chunkSkips" : 0,
                    "children" : [ 
                        {
                            "type" : "FETCH",
                            "works" : 68421,
                            "yields" : 609,
                            "unyields" : 609,
                            "invalidates" : 0,
                            "advanced" : 0,
                            "needTime" : 68421,
                            "needFetch" : 0,
                            "isEOF" : 1,
                            "alreadyHasObj" : 0,
                            "forcedFetches" : 0,
                            "matchTested" : 0,
                            "children" : [ 
                                {
                                    "type" : "IXSCAN",
                                    "works" : 68421,
                                    "yields" : 609,
                                    "unyields" : 609,
                                    "invalidates" : 0,
                                    "advanced" : 68421,
                                    "needTime" : 0,
                                    "needFetch" : 0,
                                    "isEOF" : 1,
                                    "keyPattern" : "{ _id: 1 }",
                                    "boundsVerbose" : "field #0['_id']: [MaxKey, MinKey]",
                                    "isMultiKey" : 0,
                                    "yieldMovedCursor" : 0,
                                    "dupsTested" : 0,
                                    "dupsDropped" : 0,
                                    "seenInvalidated" : 0,
                                    "matchTested" : 0,
                                    "keysExamined" : 68421,
                                    "children" : []
                                }
                            ]
                        }
                    ]
                }
            }
        ]
    },
    "cursor" : "BtreeCursor _id_ reverse",
    "n" : 0,
    "nChunkSkips" : 0,
    "nYields" : 1189,
    "nscanned" : 133295,
    "nscannedAllPlans" : 152461,
    "nscannedObjects" : 133295,
    "nscannedObjectsAllPlans" : 152461,
    "millisShardTotal" : 844,
    "millisShardAvg" : 422,
    "numQueries" : 2,
    "numShards" : 2,
    "millis" : 428
}

Probably I'm doing something wrong, not sure what... its being so frustrating

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