$geoNear, $near, and $nearSphere are not allowed in this context

Hi! I’m having the following error. Trying to filter the search using $near. The problem is that in graphQL it’s returning the following error while launching it in Heroku: “message”: “$geoNear, $near, and $nearSphere are not allowed in this context”

The Thing i’m finding really weird it that whenever I run the same code in localhost it works just fine! I really don’t know how to fix this and if someone has an idea feel free to share it with me!
if (search.within) {
const { coordinates, distance: $maxDistance } = {
coordinates: [context.longitude, context.latitude],
distance: search.within,
};
query.geo = {
$near: {
$geometry: {
type: ‘Point’,
coordinates,
},
$maxDistance,
},
};
}

const results = await Venue.paginate(query, {
page: 1,
limit: 1000,
sort,
});

Hi @Bruno_Quagliata ,

The main problem is that the graphql API goes via a user context that needs to go through app services rules defined.

There is a limitation that $near or $geonear and similar operators cannot support that :

Perhaps try to use a system function and have this query available via an http endpoint or check if a custom system resolver is a possibility to answer the geo query.

Thanks
Pavel

Hi @Pavel_Duchovny it seems like whenever I connect it to localhost Mongo using version 4.4.13 it works just fine but if I connect it to another cluster of Mongo 5.0.9 it returns the (“message”: “$geoNear, $near, and $nearSphere are not allowed in this context”) error. The program was using an older database deployed in Compose and working just fine, I migrated it to Atlas and for some time it was working but it eventually started to fail. I’m guessing this might be a Mongo issue.

@Bruno_Quagliata ,

It might be related to driver / server version .

I am not familiar with the specific but you can. Look here