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

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ