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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠