1

I have CosmosDB MongoDB-API instance.
Mongo server version = 4.0.0
Inserted documents look like:

  {
    "_id": "111",
    "fileName": "some.txt",
    "type": "ONE",
    "location": {
        "type": "MultiPoint",
        "coordinates": [
            [4, 4]
        ]
    },
    "aPoint": {
        "type": "Point",
        "coordinates": [4, 4]
    }
}

I created geo spatial indexes with mongosh(also I've tried with MongoDB Compass):

db.coll.createIndex({ location: "2dsphere" })
db.coll.createIndex({ aPoint: "2dsphere" })

result of db.coll.getIndexes()

[
  {
    v: 1,
    key: { _id: 1 },
    name: '_id_',
    ns: 'ns_name.coll'
  },
  {
    v: 1,
    key: { location: '2dsphere' },
    name: 'location_2dsphere',
    ns: 'ns_name.coll'
  },
  {
    v: 1,
    key: { aPoint: '2dsphere' },
    name: 'aPoint_2dsphere',
    ns: 'ns_name.coll'
  }
]

I have tried a lot of queries:

db.coll.find( { "aPoint": { $nearSphere : [ 4, 4 ], $maxDistance: 1000 } } )  
db.coll.find( { "aPoint.coordinates": { $nearSphere : [ 4, 4 ], $maxDistance: 1000 } } )      
db.coll.find({aPoint : { $nearSphere:{ $geometry: { type: "Point", coordinates: [4, 4] }, $maxDistance: 1000 }}} )  
db.coll.find({"aPoint.coordinates": { $nearSphere:{$geometry:{ type: "Point", coordinates: [4, 4]}, $maxDistance: 1000 }}})
  
db.coll.find({ "location": { $nearSphere : [ 4, 4 ], $maxDistance: 1000 }})  
db.coll.find({ "location.coordinates": { $nearSphere : [ 4, 4 ], $maxDistance: 1000 }})  
db.coll.find({location: { $nearSphere:{ $geometry: { type: "Point", coordinates: [4, 4] }, $maxDistance: 1000 }}} )  
db.coll.find({"location.coordinates":{$nearSphere:{ $geometry:{ type:"Point",coordinates:[4, 4]}, $maxDistance:1000 }}})  

But none of them works. The result is empty.
Do you know how I can make it work for Azure CosmosDB?
Thank you in advance.

rickhg12hs
  • 10,638
  • 6
  • 24
  • 42
Dmitry D
  • 13
  • 3
  • Does `db.coll.find({"aPoint": {"$nearSphere": {"$geometry": {"type": "Point", "coordinates": [4, 4] }, "$maxDistance": 1000 }}})` return any documents? – rickhg12hs May 06 '22 at 23:20
  • Any difference if you create the index like `db.coll.createIndex({"aPoint": "2dsphere"}, {"2dsphereIndexVersion": 3})`? – rickhg12hs May 06 '22 at 23:39
  • Hello @rickhg12hs! request db.coll.find({"aPoint": {"$nearSphere": {"$geometry": {"type": "Point", "coordinates": [4, 4] }, "$maxDistance": 1000 }}}) - return nothing – Dmitry D May 07 '22 at 14:09
  • also tried create index with (db.coll.createIndex({"aPoint": "2dsphere"}, {"2dsphereIndexVersion": 3})) - but got error "MongoServerError: 2dsphereIndexVersion" – Dmitry D May 07 '22 at 14:10
  • Would you verify the server version with `db.version()`? – rickhg12hs May 08 '22 at 22:11
  • verified db.version() --> 4.0.0 – Dmitry D May 09 '22 at 09:02
  • It seems you've tried everything. I'll watch to see if someone else can shed light on this murky corner of M$ Azure CosmosDB. – rickhg12hs May 09 '22 at 14:43
  • @DmitryD, can you share what tools you used to run your query? Specifically, did you use the standalone mongo shell locally or use mongo shell from Azure Portal? We are taking a look at this and need additional info. Thanks! – Mark Brown May 10 '22 at 18:45
  • Hello @MarkBrown! I used locally installed mongosh and MongoDB Compass. I can't use mongo shell from Azure Portal. – Dmitry D May 11 '22 at 08:25

0 Answers0