[SERVER-12904] Geospatial queries don't return results when location field is indexed along with a large object Created: 26/Feb/14  Updated: 10/Dec/14  Resolved: 26/Mar/14

Status: Closed
Project: Core Server
Component/s: Geo, Index Maintenance
Affects Version/s: 2.4.6
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Daniel López Assignee: Benety Goh
Resolution: Done Votes: 0
Labels: geospatial, indexing, multikeyIndex
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

MongoDB shell version: 2.4.6

//Saving a sample document
> db.testcollection.save({"location":

{"type":"Point","coordinates":[75.57513699999998,6.235925]}

,"largeObject":{"p1":1,"p2":1,"p3":1,"p4":1,"p5":1,"p6":1,"p7":1,"p8":1,"p9":1,"p10":1,"p11":1,"p12":1,"p13":1,"p14":1,"p15":1,"p16":1,"p17":1,"p18":1,"p19":1,"p20":1,"p21":1,"p22":1,"p23":1,"p24":1,"p25":1,"p26":1,"p27":1,"p28":1,"p29":1,"p30":1,"p31":1,"p32":1,"p33":1,"p34":1,"p35":1,"p36":1,"p37":1,"p38":1,"p39":1,"p40":1,"p41":1,"p42":1,"p43":1,"p44":1,"p45":1,"p46":1,"p47":1,"p48":1,"p49":1,"p50":1,"p51":1,"p52":1,"p53":1,"p54":1,"p55":1,"p56":1,"p57":1,"p58":1,"p59":1,"p60":1,"p61":1,"p62":1,"p63":1,"p64":1,"p65":1,"p66":1,"p67":1,"p68":1,"p69":1,"p70":1,"p71":1,"p72":1,"p73":1,"p74":1,"p75":1,"p76":1,"p77":1,"p78":1,"p79":1,"p80":1,"p81":1,"p82":1,"p83":1,"p84":1,"p85":1,"p86":1,"p87":1,"p88":1,"p89":1,"p90":1,"p91":1,"p92":1,"p93":1,"p94":1,"p95":1,"p96":1,"p97":1,"p98":1,"p99":1,"p100":1,"p101":1,"p102":1,"p103":1,"p104":1,"p105":1,"p106":1,"p107":1,"p108":1,"p109":1,"p110":1,"p111":1,"p112":1,"p113":1,"p114":1,"p115":1,"p116":1,"p117":1,"p118":1,"p119":1,"p120":1,"p121":1,"p122":1,"p123":1,"p124":1,"p125":1,"p126":1,"p127":1,"p128":1,"p129":1,"p130":1,"p131":1,"p132":1,"p133":1,"p134":1,"p135":1,"p136":1,"p137":1,"p138":1,"p139":1,"p140":1,"p141":1,"p142":1,"p143":1,"p144":1,"p145":1,"p146":1,"p147":1,"p148":1,"p149":1,"p150":1,"p151":1,"p152":1,"p153":1,"p154":1,"p155":1,"p156":1,"p157":1,"p158":1,"p159":1,"p160":1,"p161":1,"p162":1,"p163":1,"p164":1,"p165":1,"p166":1,"p167":1,"p168":1,"p169":1,"p170":1,"p171":1,"p172":1,"p173":1,"p174":1,"p175":1,"p176":1,"p177":1,"p178":1,"p179":1,"p180":1,"p181":1,"p182":1,"p183":1,"p184":1,"p185":1,"p186":1,"p187":1,"p188":1,"p189":1,"p190":1,"p191":1,"p192":1,"p193":1,"p194":1,"p195":1,"p196":1,"p197":1,"p198":1,"p199":1,"p200":1,"p201":1,"p202":1,"p203":1,"p204":1,"p205":1,"p206":1,"p207":1,"p208":1,"p209":1,"p210":1,"p211":1,"p212":1,"p213":1,"p214":1,"p215":1,"p216":1,"p217":1,"p218":1,"p219":1,"p220":1,"p221":1,"p222":1,"p223":1,"p224":1,"p225":1,"p226":1,"p227":1,"p228":1,"p229":1,"p230":1,"p231":1,"p232":1,"p233":1,"p234":1,"p235":1,"p236":1,"p237":1,"p238":1,"p239":1,"p240":1,"p241":1,"p242":1,"p243":1,"p244":1,"p245":1,"p246":1,"p247":1,"p248":1,"p249":1,"p250":1,"p251":1,"p252":1,"p253":1,"p254":1,"p255":1,"p256":1,"p257":1,"p258":1,"p259":1,"p260":1,"p261":1,"p262":1,"p263":1,"p264":1,"p265":1,"p266":1,"p267":1,"p268":1,"p269":1,"p270":1,"p271":1,"p272":1,"p273":1,"p274":1,"p275":1,"p276":1,"p277":1,"p278":1,"p279":1,"p280":1,"p281":1,"p282":1,"p283":1,"p284":1,"p285":1,"p286":1,"p287":1,"p288":1,"p289":1,"p290":1,"p291":1,"p292":1,"p293":1,"p294":1,"p295":1,"p296":1,"p297":1,"p298":1,"p299":1,"p300":1}})
//Making a geospatial query
> db.testcollection.find({location: {$geoWithin: {$centerSphere: [[75.57513699999998, 6.235925], 0.005046681806712087]}}})
//It worked!
{ "_id" : ObjectId("530d59c0fb29f59a6132b70f"), "location" :

{ "type" : "Point", "coordinates" : [ 75.57513699999998, 6.235925 ] }

, "largeObject" :

{ "p1" : 1, "p2" : 1, "p3" : 1, "p4" : 1, "p5" : 1, "p6" : 1, "p7" : 1, "p8" : 1, "p9" : 1, "p10" : 1, "p11" : 1, "p12" : 1, "p13" : 1, "p14" : 1, "p15" : 1, "p16" : 1, "p17" : 1, "p18" : 1, "p19" : 1, "p20" : 1, "p21" : 1, "p22" : 1, "p23" : 1, "p24" : 1, "p25" : 1, "p26" : 1, "p27" : 1, "p28" : 1, "p29" : 1, "p30" : 1, "p31" : 1, "p32" : 1, "p33" : 1, "p34" : 1, "p35" : 1, "p36" : 1, "p37" : 1, "p38" : 1, "p39" : 1, "p40" : 1, "p41" : 1, "p42" : 1, "p43" : 1, "p44" : 1, "p45" : 1, "p46" : 1, "p47" : 1, "p48" : 1, "p49" : 1, "p50" : 1, "p51" : 1, "p52" : 1, "p53" : 1, "p54" : 1, "p55" : 1, "p56" : 1, "p57" : 1, "p58" : 1, "p59" : 1, "p60" : 1, "p61" : 1, "p62" : 1, "p63" : 1, "p64" : 1, "p65" : 1, "p66" : 1, "p67" : 1, "p68" : 1, "p69" : 1, "p70" : 1, "p71" : 1, "p72" : 1, "p73" : 1, "p74" : 1, "p75" : 1, "p76" : 1, "p77" : 1, "p78" : 1, "p79" : 1, "p80" : 1, "p81" : 1, "p82" : 1, "p83" : 1, "p84" : 1, "p85" : 1, "p86" : 1, "p87" : 1, "p88" : 1, "p89" : 1, "p90" : 1, "p91" : 1, "p92" : 1, "p93" : 1, "p94" : 1, "p95" : 1, "p96" : 1, "p97" : 1, "p98" : 1, "p99" : 1, "p100" : 1, "p101" : 1, "p102" : 1, "p103" : 1, "p104" : 1, "p105" : 1, "p106" : 1, "p107" : 1, "p108" : 1, "p109" : 1, "p110" : 1, "p111" : 1, "p112" : 1, "p113" : 1, "p114" : 1, "p115" : 1, "p116" : 1, "p117" : 1, "p118" : 1, "p119" : 1, "p120" : 1, "p121" : 1, "p122" : 1, "p123" : 1, "p124" : 1, "p125" : 1, "p126" : 1, "p127" : 1, "p128" : 1, "p129" : 1, "p130" : 1, "p131" : 1, "p132" : 1, "p133" : 1, "p134" : 1, "p135" : 1, "p136" : 1, "p137" : 1, "p138" : 1, "p139" : 1, "p140" : 1, "p141" : 1, "p142" : 1, "p143" : 1, "p144" : 1, "p145" : 1, "p146" : 1, "p147" : 1, "p148" : 1, "p149" : 1, "p150" : 1, "p151" : 1, "p152" : 1, "p153" : 1, "p154" : 1, "p155" : 1, "p156" : 1, "p157" : 1, "p158" : 1, "p159" : 1, "p160" : 1, "p161" : 1, "p162" : 1, "p163" : 1, "p164" : 1, "p165" : 1, "p166" : 1, "p167" : 1, "p168" : 1, "p169" : 1, "p170" : 1, "p171" : 1, "p172" : 1, "p173" : 1, "p174" : 1, "p175" : 1, "p176" : 1, "p177" : 1, "p178" : 1, "p179" : 1, "p180" : 1, "p181" : 1, "p182" : 1, "p183" : 1, "p184" : 1, "p185" : 1, "p186" : 1, "p187" : 1, "p188" : 1, "p189" : 1, "p190" : 1, "p191" : 1, "p192" : 1, "p193" : 1, "p194" : 1, "p195" : 1, "p196" : 1, "p197" : 1, "p198" : 1, "p199" : 1, "p200" : 1, "p201" : 1, "p202" : 1, "p203" : 1, "p204" : 1, "p205" : 1, "p206" : 1, "p207" : 1, "p208" : 1, "p209" : 1, "p210" : 1, "p211" : 1, "p212" : 1, "p213" : 1, "p214" : 1, "p215" : 1, "p216" : 1, "p217" : 1, "p218" : 1, "p219" : 1, "p220" : 1, "p221" : 1, "p222" : 1, "p223" : 1, "p224" : 1, "p225" : 1, "p226" : 1, "p227" : 1, "p228" : 1, "p229" : 1, "p230" : 1, "p231" : 1, "p232" : 1, "p233" : 1, "p234" : 1, "p235" : 1, "p236" : 1, "p237" : 1, "p238" : 1, "p239" : 1, "p240" : 1, "p241" : 1, "p242" : 1, "p243" : 1, "p244" : 1, "p245" : 1, "p246" : 1, "p247" : 1, "p248" : 1, "p249" : 1, "p250" : 1, "p251" : 1, "p252" : 1, "p253" : 1, "p254" : 1, "p255" : 1, "p256" : 1, "p257" : 1, "p258" : 1, "p259" : 1, "p260" : 1, "p261" : 1, "p262" : 1, "p263" : 1, "p264" : 1, "p265" : 1, "p266" : 1, "p267" : 1, "p268" : 1, "p269" : 1, "p270" : 1, "p271" : 1, "p272" : 1, "p273" : 1, "p274" : 1, "p275" : 1, "p276" : 1, "p277" : 1, "p278" : 1, "p279" : 1, "p280" : 1, "p281" : 1, "p282" : 1, "p283" : 1, "p284" : 1, "p285" : 1, "p286" : 1, "p287" : 1, "p288" : 1, "p289" : 1, "p290" : 1, "p291" : 1, "p292" : 1, "p293" : 1, "p294" : 1, "p295" : 1, "p296" : 1, "p297" : 1, "p298" : 1, "p299" : 1, "p300" : 1 }

}
//Creating the compound index
> db.testcollection.ensureIndex(

{location: '2dsphere', largeObject: 1}

)
//Making the same geospatial query again
> db.testcollection.find({location: {$geoWithin: {$centerSphere: [[75.57513699999998, 6.235925], 0.005046681806712087]}}})
> //We got no results

Participants:

 Description   

When a compound index is created in a collection holding a document with a GeoJSON field and a large object property (with a lot of keys), the geospatial queries don't return results.

Imagine the following document:

{
location:

{ type: "Point", coordinates: [<lng>, <lat>] }

,
largeObject:

{...}

}

And assume it's held by a collection with a compound index like this:

{location: "2dsphere", largeObject: 1}

If the `largeObject` property contains too many keys, then the document won't be return in geospatial queries.



 Comments   
Comment by Daniel López [ 26/Mar/14 ]

Thank you so much!

Comment by Benety Goh [ 26/Mar/14 ]

There's a 1024-byte limit on the index key:

http://docs.mongodb.org/manual/reference/limits/#Index-Key

In 2.4, the document is not getting inserted into the index and that's why you're not getting any results.

In 2.6, you will get the following error when you try to create the compound index:

Btree::insert: key too large to index ...

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