[SERVER-1669] Performing Queries with GeoSpatial Indexes Cause Non-Geospatial results to not return items without location data. Created: 24/Aug/10  Updated: 12/Jul/16  Resolved: 26/Aug/10

Status: Closed
Project: Core Server
Component/s: Geo, Index Maintenance
Affects Version/s: 1.4.4, 1.6.1
Fix Version/s: 1.7.0

Type: Bug Priority: Major - P3
Reporter: Sasank Reddy Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

PyMongo, 1.6.1 and 1.4.4 MongoDB, Ubuntu


Attachments: File geo_test.py    
Operating System: ALL
Participants:

 Description   

I created a simple python script to test out geospatial indexes which
is located here: http://pastie.org/1112344 (and also attached)

Basically, what I'm doing in the script is the following:

Creating a Geo Index for the "location" field.
I add three entries which contain issue and created fields (issue
increases from 0 to 2)
I add three entries which contain issue, created, and location fields
(issue increase from 0 to 2)

1.) I do a find with no query arguments (results are all 6 documents)

  • Pass.
    2.) I do a find where issue is 0 (results are 2 documents - one
    without location, one with location) - Pass.
    3.) I do a find with a location near query (results are 3 documents -
    the three documents with location) - Pass.
    4.) I do a find where issue is 0 (results are 2 documents - one
    without location, one with location) - Pass.
    5.) I do a find with a location near query and where issue is 0
    (results are 1 document - one with location and issue of 0) - Pass.
    6.) I do a find with issue is 0 (results are 1 document - one with
    location) - FAIL - This should of returned the same thing as query 5
    and query 7.
    7.) I do a find with no query arguments (results are all 6 documents)
  • Pass

What I don't understand is why doing a query with a geo index and
another parameter causes that parameter not to show up in a non-geo
index based query. In this case, the query described in (6) results
in the wrong output. It should also return the document that does not
have a location field.

The output of my python program is shown below. Can be reproduced on
both 1.4.4 and 1.6.1 with PyMongo 1.8.1.


Create Geo Index for location
Adding values without location and with location

Print Everything

{u'_id': ObjectId('4c73ce215c59731428000000'), u'issue': u'0', u'created': datetime.datetime(2010, 8, 24, 13, 50, 25, 778000)} {u'_id': ObjectId('4c73ce215c59731428000001'), u'issue': u'1', u'created': datetime.datetime(2010, 8, 24, 13, 50, 25, 778000)} {u'_id': ObjectId('4c73ce215c59731428000002'), u'issue': u'2', u'created': datetime.datetime(2010, 8, 24, 13, 50, 25, 778000)} {u'_id': ObjectId('4c73ce215c59731428000003'), u'issue': u'0', u'location': [34.0, -118.0], u'created': datetime.datetime(2010, 8, 24, 13, 50, 25, 778000)} {u'_id': ObjectId('4c73ce215c59731428000004'), u'issue': u'1', u'location': [34.0, -118.0], u'created': datetime.datetime(2010, 8, 24, 13, 50, 25, 778000)} {u'_id': ObjectId('4c73ce215c59731428000005'), u'issue': u'2', u'location': [34.0, -118.0], u'created': datetime.datetime(2010, 8, 24, 13, 50, 25, 779000)}

Print Specific Item where issue is 0

{u'_id': ObjectId('4c73ce215c59731428000000'), u'issue': u'0', u'created': datetime.datetime(2010, 8, 24, 13, 50, 25, 778000)} {u'_id': ObjectId('4c73ce215c59731428000003'), u'issue': u'0', u'location': [34.0, -118.0], u'created': datetime.datetime(2010, 8, 24, 13, 50, 25, 778000)}

Print Geo Version where location is near 34.12 and -118.12

{u'_id': ObjectId('4c73ce215c59731428000005'), u'issue': u'2', u'location': [34.0, -118.0], u'created': datetime.datetime(2010, 8, 24, 13, 50, 25, 779000)} {u'_id': ObjectId('4c73ce215c59731428000004'), u'issue': u'1', u'location': [34.0, -118.0], u'created': datetime.datetime(2010, 8, 24, 13, 50, 25, 778000)} {u'_id': ObjectId('4c73ce215c59731428000003'), u'issue': u'0', u'location': [34.0, -118.0], u'created': datetime.datetime(2010, 8, 24, 13, 50, 25, 778000)}

Print Specific Item where issue is 0

{u'_id': ObjectId('4c73ce215c59731428000000'), u'issue': u'0', u'created': datetime.datetime(2010, 8, 24, 13, 50, 25, 778000)} {u'_id': ObjectId('4c73ce215c59731428000003'), u'issue': u'0', u'location': [34.0, -118.0], u'created': datetime.datetime(2010, 8, 24, 13, 50, 25, 778000)}

Print Geo Sepecic Versions where location is near 34.12 and -118.12
and issue is 0

{u'_id': ObjectId('4c73ce215c59731428000003'), u'issue': u'0', u'location': [34.0, -118.0], u'created': datetime.datetime(2010, 8, 24, 13, 50, 25, 778000)}

Print Specific Item where issue is 0

{u'_id': ObjectId('4c73ce215c59731428000003'), u'issue': u'0', u'location': [34.0, -118.0], u'created': datetime.datetime(2010, 8, 24, 13, 50, 25, 778000)}

Print Everything

{u'_id': ObjectId('4c73ce215c59731428000000'), u'issue': u'0', u'created': datetime.datetime(2010, 8, 24, 13, 50, 25, 778000)} {u'_id': ObjectId('4c73ce215c59731428000001'), u'issue': u'1', u'created': datetime.datetime(2010, 8, 24, 13, 50, 25, 778000)} {u'_id': ObjectId('4c73ce215c59731428000002'), u'issue': u'2', u'created': datetime.datetime(2010, 8, 24, 13, 50, 25, 778000)} {u'_id': ObjectId('4c73ce215c59731428000003'), u'issue': u'0', u'location': [34.0, -118.0], u'created': datetime.datetime(2010, 8, 24, 13, 50, 25, 778000)} {u'_id': ObjectId('4c73ce215c59731428000004'), u'issue': u'1', u'location': [34.0, -118.0], u'created': datetime.datetime(2010, 8, 24, 13, 50, 25, 778000)} {u'_id': ObjectId('4c73ce215c59731428000005'), u'issue': u'2', u'location': [34.0, -118.0], u'created': datetime.datetime(2010, 8, 24, 13, 50, 25, 779000)}

 Comments   
Comment by auto [ 15/Sep/10 ]

Author:

{'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}

Message: when using a special index, don't record because may screw up later SERVER-1669
http://github.com/mongodb/mongo/commit/24f373dc2728d87a65f0e04fe3eae1537f3c306e

Comment by auto [ 26/Aug/10 ]

Author:

{'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}

Message: when using a special index, don't record because may screw up later SERVER-1669
http://github.com/mongodb/mongo/commit/65078c15cbbc4f4ca44a25eda7d619abd37ee447

Comment by Sasank Reddy [ 24/Aug/10 ]

I reproduced it on the shell as well. Here it is. Notice the different results you get for > db.mc.find(

{'issue':0}

) before and after I do the find with the location query. That is the problem.

> use mdb
switched to db mdb
> db.createCollection("mc")

{ "ok" : 1 }

> db.mc.ensureIndex(

{loc:"2d"}

)

> db.mc.insert(

{'issue':0}

)
> db.mc.insert(

{'issue':1}

)
> db.mc.insert(

{'issue':2}

)
> db.mc.insert(

{'issue':2, 'loc':[30.12,-118]}

)
> db.mc.insert(

{'issue':1, 'loc':[30.12,-118]}

)
> db.mc.insert(

{'issue':0, 'loc':[30.12,-118]}

)

> db.mc.find()

{ "_id" : ObjectId("4c73f6cd6a4cdeb8c2f920ff"), "issue" : 0 } { "_id" : ObjectId("4c73f6cf6a4cdeb8c2f92100"), "issue" : 1 } { "_id" : ObjectId("4c73f6d16a4cdeb8c2f92101"), "issue" : 2 } { "_id" : ObjectId("4c73f6f36a4cdeb8c2f92102"), "issue" : 2, "loc" : [ 30.12, -118 ] } { "_id" : ObjectId("4c73f6f86a4cdeb8c2f92103"), "issue" : 1, "loc" : [ 30.12, -118 ] } { "_id" : ObjectId("4c73f6fd6a4cdeb8c2f92104"), "issue" : 0, "loc" : [ 30.12, -118 ] }

> db.mc.find(

{'issue':0}

)

{ "_id" : ObjectId("4c73f6cd6a4cdeb8c2f920ff"), "issue" : 0 } { "_id" : ObjectId("4c73f6fd6a4cdeb8c2f92104"), "issue" : 0, "loc" : [ 30.12, -118 ] }

> db.mc.find({'issue':0,'loc':{$near:[30.12,-118]}})

{ "_id" : ObjectId("4c73f6fd6a4cdeb8c2f92104"), "issue" : 0, "loc" : [ 30.12, -118 ] }

> db.mc.find(

{'issue':0}

)

{ "_id" : ObjectId("4c73f6fd6a4cdeb8c2f92104"), "issue" : 0, "loc" : [ 30.12, -118 ] }

> db.mc.find()

{ "_id" : ObjectId("4c73f6cd6a4cdeb8c2f920ff"), "issue" : 0 } { "_id" : ObjectId("4c73f6cf6a4cdeb8c2f92100"), "issue" : 1 } { "_id" : ObjectId("4c73f6d16a4cdeb8c2f92101"), "issue" : 2 } { "_id" : ObjectId("4c73f6f36a4cdeb8c2f92102"), "issue" : 2, "loc" : [ 30.12, -118 ] } { "_id" : ObjectId("4c73f6f86a4cdeb8c2f92103"), "issue" : 1, "loc" : [ 30.12, -118 ] } { "_id" : ObjectId("4c73f6fd6a4cdeb8c2f92104"), "issue" : 0, "loc" : [ 30.12, -118 ] }
Generated at Thu Feb 08 02:57:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.