0

I have an Azure CosmosDB with a collection restaurants where a field geoJSON specifies the location of a restaurant in geoJSON format. I am using the MongoDB API to access this.

When I log into the DB using the mongo shell, I am able to see all the documents using db.restaurants.find(). I created a 2dsphere geospatial index using db.restaurants.createIndex( {geoJSON: "2dsphere"}).

output:

{
    "_t" : "CreateIndexesResponse",
    "ok" : 1,
    "createdCollectionAutomatically" : false,
    "numIndexesBefore" : 3,
    "numIndexesAfter" : 4
}

However, upon running db.restaurants.getIndexes(), I still see only three indexes. This question says that indexing is not allowed. Is this still the case?

Furthermore, there seems to be an index called

{
            "v" : 1,
            "key" : {
                    "DocumentDBDefaultIndex" : "2dsphere"
            },
            "name" : "DocumentDBDefaultIndex_2dsphere",
            "ns" : "<redacted>"
}

,but executing a geospatial query returns nothing.

db.restautants.find({DocumentDBDefaultIndex: {$near: {$geometry: {type: "Point", coordinates: [24.9430111, 60.166608]}, $maxDistance: 1000}}})

How can I execute geospatial queries against this index using the mongo shell? Is this a bug in CosmosDB?

2 Answers 2

1

According to your description, I checked this issue on my side. For a quick way, I use MongoChef with the Azure Cosmos DB. Based on my test, db.brucetest1.createIndex({loc:"2dsphere"}) could not be applied to the collection. Moreover, I found DocumentDB automatically creates a 2dsphere index on the location field DocumentDBDefaultIndex, then I drop my documents, and insert the documents as follows:

db.brucetest.insertMany([
   {DocumentDBDefaultIndex : { type: "Point", coordinates: [ -73.97, 40.77 ] },name: "Central Park",category : "Parks"},
   {DocumentDBDefaultIndex : { type: "Point", coordinates: [ -73.88, 40.78 ] },name: "La Guardia Airport",category : "Airport"}
])

With the following query, I could encounter your issue:

db.brucetest.find({DocumentDBDefaultIndex:{$near:{$geometry:{type:"Point",coordinates:[-73.88, 40.78]}}}})

Based on the similar issue your mentioned, I assumed that the creating/updating index and Geospatial indexes querying features have not been implemented in the MongoDB Compatibility layer of Azure CosmosDB. Moreover, you could add your feedback here or wait for these features released.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I just decided to go with the native DocumentDB API in my application. There is a learning curve to it, so it's slowing me down. I hope it gets added quickly.
0

Geospatial IS currently supported with the MongoDB API. Please see the Geospatial operators section here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.