AWS 2dsphere limitation

2

Hi all,

I am using DocumentDB with Mongo support on AWS and we are having documents that include geolocation. We have read the documentation of AWS for mongo support here but despite it says that it's supported we are receiving error during the creation of the index.

The error we are getting when creating the index is : "Command createIndexes failed : Index type not supported : 2dsphere"

The c# code that should generate the index is the below :

var prefixIndexName = nameof(Account.Address)+"."+nameof(Account.Address.Geolocation);
if (!accountCollection.ExistIndex(prefixIndexName+"_2dsphere"))
{
       Console.WriteLine("Seeding Geolocation Geo2DSphere Index ...");
       var geoLocation = new StringFieldDefinition<Account>(prefixIndexName);
       var indexDefinition = new IndexKeysDefinitionBuilder<Account>().Geo2DSphere(geoLocation);
       var indexModel = new CreateIndexModel<Account>(indexDefinition, new CreateIndexOptions { Background = false });
       accountCollection.CreateIndex(indexModel);
}

The field that we are trying to add in the index is the "Address" and it looks like this :

"Address":  {
        "CountryId": number, 
        "PostCode": string,
        "AddressLine1": string,
        "AddressLine2": string,
        "City": string,
        "State": string,
        "Geolocation": {
            "type": "Point",
            "coordinates": decimal[] // e.g. [xx.xxxxxxx, xx.xxxxxxx]
        }
    }

The code is working on my local MongoDB installation, so I believe I am missing something to make it run on AWS.

Any help you could provide is valuable, thanks in advance for your time!

  • 2dsphere indexes are indeed supported, have you tried creating the index from the mongo shell? The limitation is that is supported only for GeoJSON type Point, not for polygons or multi-polygons. Do you have other geospatial shapes, other than points, in the collection? However, if that's the case, the error would be something like "Unsupported GeoJson type" when creating the 2dspehere index.

已提问 2 年前234 查看次数
1 回答
1

Please check if you are using documentDB elastic cluster, 2dsphere index is not supported in Elastic clusters. https://docs.aws.amazon.com/documentdb/latest/developerguide/mongo-apis.html#mongo-apis-index

AWS
已回答 10 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则