Geospacial 'within box' query returning error 'need an area > 0'

42 views
Skip to first unread message

Sosh

unread,
May 4, 2012, 6:06:13 AM5/4/12
to mongodb-user
Hi,

I have a collection with a Geospacial index for it's a simple catesian
system (only integers).

I have my index set up like this:
dbMapData.ensureIndex([{ loc : "2d" }, { min : -10000000000 , max :
10000000000 }], true, function(err, res){}); //Abitrary large min/max

And my query:
dbMapData.find({"loc" : {"$within" : {"$box" :
box}}}).toArray(function (err, array) {...

I'm looping though diffent box values. This seems to work well, until
I reach a certain y value, then I am hit with the 'need an area > 0'
error. However, I don't understand why I'm getting this error, as the
query that causes it is no different to the others. I was wondering
if it might be an index min/max issue?

My debug output is below (box coords are x1,y1,x2,y2):

maprange request. box: -50,0,99,149
maprange request took 9 ms to query

maprange request. box: -50,50,99,199
maprange request took 6 ms to query

maprange request. box: -50,100,99,249
maprange request took 6 ms to query

maprange request. box: -50,150,99,299
maprange request took 1 ms to query

maprange request. box: -50,200,99,349
maprange request took 1 ms to query

maprange request. box: -50,250,99,399
maprange request took 24 ms to query

maprange request. box: -50,300,99,449
maprange request took 2 ms to query

maprange request. box: -50,350,99,499
maprange request took 1 ms to query

maprange request. box: -50,400,99,549
maprange request took 18 ms to query

maprange request. box: -50,450,99,599
maprange request took 6 ms to query

maprange request. box: -50,500,99,649

need an area > 0


Thank you!

Mathias Stearn

unread,
May 4, 2012, 12:11:00 PM5/4/12
to mongod...@googlegroups.com
Why are you using such a wide range of min and max? If you really need that much range, I'd suggest adding bits:32 to the index configuration (default is 26) to ensure that you have sufficient precision for dealing with small numbers.

Sosh

unread,
May 4, 2012, 1:14:12 PM5/4/12
to mongod...@googlegroups.com
Ok yes, I probably need to do that, but it doesn't seem to be related to this problem.  I've changed to -10 000, 10 000 and still get exactly the same issue.

Mathias Stearn

unread,
May 4, 2012, 1:17:29 PM5/4/12
to mongod...@googlegroups.com
Could you post the raw output running in the mongodb shell?

Sosh

unread,
May 4, 2012, 1:33:53 PM5/4/12
to mongod...@googlegroups.com
Hmm.  Ok, I shouldn't have been so hasty.  There were a bunch of 2d indexes on that collection with different values (who knows where from).  I've deleted the indexes and re-ensured an index of -10 000, 10 000.   When I run the test again it spits the error out at box= -100,200,49,349   which seems suspiciously close to mongos default 2d index range of -180, 180 right?  Could it be ignoring my index?  

Do you know what the max index range is when 'bits' is left at the default value?  I'm going to change bits to 32 now (but I don't think I really need to for 10 000).  Will try and get you the console output too, but not familiar with this.

Thanks.

Sosh

unread,
May 4, 2012, 1:37:47 PM5/4/12
to mongod...@googlegroups.com
Bits:32 Didn't help, still failing at   box= -100,200,49,349.

Sosh

unread,
May 4, 2012, 2:41:18 PM5/4/12
to mongod...@googlegroups.com
Here's the relevant log file output:

Fri May 04 19:35:46 [conn8] build index tworld.map { loc: "2d", min: -10000, max: 10000, bits: 32 }
Fri May 04 19:35:46 [conn8] build index done 138 records 0 secs
Fri May 04 19:36:03 [clientcursormon] mem (MB) res:63 virt:140 mapped:96
Fri May 04 19:36:18 [conn8] assertion 13064 need an area > 0  ns:tworld.map query:{ loc: { $within: { $box: [ [ -100, 200 ], [ 49, 349 ] ] } } }

Mathias Stearn

unread,
May 4, 2012, 5:37:05 PM5/4/12
to mongod...@googlegroups.com
It looks like you put the min,max and bits options in the index spec rather than in the options field. The correct syntax is something like this:

db.map.ensureIndex({ loc: "2d"}, {min: -10000, max: 10000, bits: 32 })

Sosh

unread,
May 5, 2012, 4:56:56 AM5/5/12
to mongod...@googlegroups.com
Hmm strange, that seems to be exactly the way I'm specifying it.  From my code (before I put the bits in):

dbMapData.ensureIndex([{ loc : "2d" }, { min : -10000 , max : 10000, bits : 32 } .....

Perhaps this is a problem with the driver?  Is there any way of forcing it so the the second parameter set is associated with the options field?

Sosh

unread,
May 5, 2012, 6:42:49 AM5/5/12
to mongod...@googlegroups.com
Doh! Got it. As usual a stupid mistake on my part.  Was simply using wrong syntax for ensureIndex call.  Works great now.   Thank you for your help Mathias!
Reply all
Reply to author
Forward
0 new messages