[SERVER-2331] Allow more than one geo index per collection Created: 05/Jan/11  Updated: 06/Dec/22  Resolved: 01/Feb/16

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

Type: Improvement Priority: Minor - P4
Reporter: Brian Hempel Assignee: Backlog - Query Team (Inactive)
Resolution: Done Votes: 20
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-3653 Issues with multiple spatial indexes Closed
is duplicated by SERVER-7877 support more than one geo index per c... Closed
Related
Assigned Teams:
Query
Backwards Compatibility: Fully Compatible
Participants:

 Description   

It'd be nice to allow more than one geospatial index in a collection. I currently have a collection where this might be useful--two different keys in a document whose locations represent different things.



 Comments   
Comment by Siyuan Zhou [ 08/Feb/16 ]

For $geoNear command and $geoNear aggregation, it returns an error.

It's highly recommended to use $geoNear query operator rather than $geoNear command unless you need the $distance output or run on a sharding cluster. $geoNear query operator supports multiple indexes, because it allows users to specify the field name. For $geoNear aggregation operator, it's a limitation without workaround.

Comment by Robert Pocklington [ 01/Feb/16 ]

@Neville - that was the reason I referenced this issue. It's confusing as you can create multiple indexes, but only one will ever be used (the JIRA issue could be updated to "$geoNear doesn't work with multiple geo indexes") as per MongoDB docs. I am using legacy 2d coordinates - are you saying this isn't a limitation with 2dsphereIndexVersion v2?

Comment by Neville Dipale [ 01/Feb/16 ]

I was going to ask about that, which index is used when there are multiple?

Comment by Ramon Fernandez Marina [ 01/Feb/16 ]

rpocklin, as nevi_me correctly points out it is already possible to have more than one geo index per collection. Here's a sample output of getIndexes() on a collection with two geo indices:

> db.foo.getIndexes()
[
        {
                "v" : 1,
                "key" : {
                        "_id" : 1
                },
                "name" : "_id_",
                "ns" : "test.foo"
        },
        {
                "v" : 1,
                "key" : {
                        "loc" : "2dsphere"
                },
                "name" : "loc_2dsphere",
                "ns" : "test.foo",
                "2dsphereIndexVersion" : 3
        },
        {
                "v" : 1,
                "key" : {
                        "pos" : "2dsphere"
                },
                "name" : "pos_2dsphere",
                "ns" : "test.foo",
                "2dsphereIndexVersion" : 3
        }
]

Please note that the $geoNear command and aggregation operator have some limitations:

The $geoNear requires that a collection have at most only one 2d index and/or only one 2dsphere index.

Comment by Neville Dipale [ 22/Jan/16 ]

Can someone explain what the gist of the issue is? I have a collection that has 3 geo indices (2dsphereIndexVersion 2). Is the issue allowing this to happen, or is it for the legacy 2d index?

Comment by Robert Pocklington [ 10/Mar/15 ]

IMO this is a major limitation of using geo searching in MongoDB. It'd be great to understand why this limitation exists and some kind of estimate of when this will get looked at.

Comment by Nicholas Knize [ 19/Jul/11 ]

I'm not sure I understand the wording for this issue. I assume the request is more than 1 geoIndex per document in a collection. This dovetails nicely w/ SERVER-3325 and SERVER-2874 for allowing multi-point w/ $elemMatch and polygon intersect search, respectively.

Comment by Nicholas Knize [ 19/Jul/11 ]

Anyone else working this? I'm in need of this capability and if no one is working on it I'm going to start, but I'm not looking to duplicate an in-work effort.

Generated at Thu Feb 08 02:59:39 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.