Hi all,
I am looking to use Atlas Search and the near
operator to find records that satisfy both the search criteria and are near a given geo point. I created a 2d
index for the field location
, which follows the structure mentioned in the documentation.
When I try to find documents using only the near
function, everything works fine. Similarly, using the search query with Atlas Search also works correctly. However, I am struggling to use both operators in the same aggregation query.
The error I encounter is:
Failed to run this query. Reason: geoWithin requires path 'location' to be indexed as 'geo'
The query I am running is:
{
$search: {
index: "default",
compound: {
must: [
{
text: { query: "text", path: "*" },
},
{
near: {
path: "location",
origin: {
type: "Point",
coordinates: [
45.464203, 9.189982,
],
},
pivot: 100000,
},
},
],
},
},
},
]`
location field:
![Capture|690x179](upload://1uFsgeGJfrga3yppxmekVT4YbBO.png)
Index field
![Capture|690x129](upload://9M9ciP3d9PwP1gVTKZpd5cYBynB.png)
Atlas Search index:
![Capture|690x177](upload://fHEoJY4IUKezWFRrODDerYQBMkZ.png)
Query error:
![Capture|690x426](upload://7zUViZDyGzTf6QJPU4dva39LGZx.png)
The same error was also raised from NodeJs.
Any idea what I am doing wrong?
Thanks in advance.