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.

asked 2 years ago231 views
1 Answer
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
answered 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions