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 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南