I started to work with MongoDB API, beacause we are using Azure Cosmos DB. Tried examples using $near in MongoDB with the basic structure {key:"A": localtion:{type:"Point", coordinates:[1,2]}}, and works well. The ploblem is when i need to use an array of locations.
I'm triying to execute this query without result. What i'm doing bad?
db.places.insert( {
id:1,
name: "AAAAAAAAAAA",
locals:[
{
location: { type: "Point", coordinates: [-73.9928, 40.7191 ] },
}
],
category: "Parks"
} );
db.places.insert( {
id:2,
name: "BBBBBBBBBBB",
locals:[
{
location: { type: "Point", coordinates: [-73.9928, 40.7193 ] },
}
],
category: "Parks"
} );
db.places.insert( {
id:3,
name: "CCCCCCCCCCCCC",
locals:[
{
location: { type: "Point", coordinates: [ -73.9375, 40.8303 ] },
}
],
category: "Parks"
} );
//Create index
db.places.createIndex({ "locals.location" : "2dsphere" })
//Query without result
db.places.find(
{
"locals.location":
{ $near:
{
$geometry: { type: "Point", coordinates: [ -73.9375, 40.8303 ] },
$minDistance: 1000,
$maxDistance: 5000
}
}
}
)
The places has many locals, that's why I can have many objects inside.
I hope some one can help me.
Cheers.
Based on my test with your sample data, also got empty result as same as you. Per my knowledge, CosmosDB just supports a subset of the MongoDB API and translates requests into the CosmosDB SQL equivalent. CosmosDB has some different behaviours and results. But the onus is on CosmosDB to improve their emulation of MongoDB.
Certainly, you could add feedback here to submit your requirements or consider using MongoDB Atlas on Azure if you'd like full MongoDB feature support.