[SERVER-11535] Geo Query with $within and {$uniqueDocs:false} does not return matched documents multiple times. Created: 02/Nov/13  Updated: 10/Mar/14  Resolved: 06/Nov/13

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.5.3
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Robert Moore Assignee: Gianfranco Palumbo
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux.


Issue Links:
Related
related to DOCS-2195 Update $uniqueDocs for 2.5.3 Closed
is related to SERVER-11379 require field name in geoNear, remove... Closed
Backwards Compatibility: Major Change
Operating System: ALL
Steps To Reproduce:

MongoDB shell version: 2.5.3
connecting to: test
Server has startup warnings: 
2013-11-02T14:55:59.666-0400 [initandlisten] 
2013-11-02T14:55:59.666-0400 [initandlisten] ** NOTE: This is a development version (2.5.3) of MongoDB.
2013-11-02T14:55:59.666-0400 [initandlisten] **       Not recommended for production.
2013-11-02T14:55:59.666-0400 [initandlisten] 
> 
> db.geo.createIndex( { p : "2d" } )
> db.geo.insert( { p : [ [ 5, 5 ], [ 6, 6 ] ] } )
> db.geo.insert( { p : [8,8] } )
> db.geo.insert( { p : [4,4] } )
> db.geo.find( { p : { "$within" : { "$box" : [ [3, 3], [7,7] ], "$uniqueDocs" : false } } } )
{ "_id" : ObjectId("52754c0c5d197882730594ab"), "p" : [  [  5,  5 ],  [  6,  6 ] ] }
{ "_id" : ObjectId("52754c305d197882730594ad"), "p" : [  4,  4 ] }
 
// Should have returned the first document (52754c0c5d197882730594ab) twice.

Participants:

 Description   

The semantics for 2.5.3 for a geo query using a '2d' index have changed when requesting that documents matching the region multiple times be returned multiple times.

While



 Comments   
Comment by Gianfranco Palumbo [ 06/Nov/13 ]

I've created and linked this DOCS-2195 ticket.

Comment by Robert Moore [ 06/Nov/13 ]

Gianfranco,

No need for a CS ticket. I will figure something out.

I do think this should be documented in the release notes. Can we convert this ticket to a DOCS ticket to get those updated?

Rob.

Comment by Gianfranco Palumbo [ 05/Nov/13 ]

Hi Robert,

UniqueDocs / UniqueLocs is going away in 2.6 - the semantics interfere badly with our general multikey index semantics.
See SERVER-11379

If you want multiple results, you can/should add multiple documents with different location fields.

If this has a commercial impact please open a CS ticket and we can discuss it there in more detail.

Regards,
Gianfranco

Comment by Gianfranco Palumbo [ 04/Nov/13 ]

While you can use $uniqueDocs only with the $geoWithin and $near operators, I believe you're right in your comment example:

This is also not working as expected

db.geo.createIndex( { p : "2d" } )
db.geo.insert( { '_id' : 'P1', p : [ [ 4,  4 ],  [ 5,  5 ] ] } );
db.geo.find( { p : { "$geoWithin" : { "$box" : [ [3, 3], [7,7] ], "$uniqueDocs" : false } } } )
{ "_id": "P1", "p": [ [ 4, 4 ], [ 5, 5 ] ] }
// should be here twice since it's a multi-location document

Comment by Robert Moore [ 02/Nov/13 ]

This is also broken with the $geoWithin operator:

MongoDB shell version: 2.5.3
connecting to: test
Server has startup warnings: 
2013-11-02T15:59:46.372-0400 [initandlisten] 
2013-11-02T15:59:46.372-0400 [initandlisten] ** NOTE: This is a development version (2.5.3) of MongoDB.
2013-11-02T15:59:46.372-0400 [initandlisten] **       Not recommended for production.
2013-11-02T15:59:46.372-0400 [initandlisten] 
> db.geo.createIndex( { "p" : "2dsphere" } )
> db.geo.insert( { '_id' : 'P1', p : { type : 'MultiPoint', coordinates : [ [ 2,  2 ],  [ 1,  1 ] ] } } );
> db.geo.find( { p : { '$geoWithin' : { '$geometry' : { type : 'Polygon', coordinates : [ [ [ 0,  0 ],  [ 3,  0 ],  [ 3,  3 ],  [ 0,  3 ],  [ 0,  0 ] ] ] }, '$uniqueDocs' : false } } } );
{ "_id" : "P1", "p" : { "type" : "MultiPoint", "coordinates" : [  [  2,  2 ],  [  1,  1 ] ] } }

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