Open santigandolfo opened 1 year ago
After reading the source code and mongo's docs (and with the help of ChatGPT) I've fould the following:
The reason why when I do the engine.find
it fails is because the find method uses internally an aggregation pipeline where the find queries are set inside a $match stage. And because "You cannot use $near or $nearSphere in
$match queries as part of the aggregation pipeline" (from the MongoDB docs) then that's why the query fails (It would be nice if the OperationFailure error said this insead of the more generic "...are not allowed in this context").
The docs suggest to:
"
Use $geoNear stage instead of the $match stage.
Use $geoWithin query operator with $center or $centerSphere in the $match stage. "
Is there a way to add the geoNear stage to the _prepare_find_pipeline
method? I don't know what the best way to do it, if the queries should go in the queries parameter or in a separate one (or if there should be a different find method that allows this kind of queries).
Bug
I'm getting a
pymongo.errors.OperationFailure: $geoNear, $near, and $nearSphere are not allowed in this context
error when trying to find using the $near operator.Current Behavior
If I have defined the following classes:
And execute this query:
The following exception is raised:
Expected behavior
The query should return a list of Instructions.
Environment
0.9.2
5.0.14 (Mongo Atlas)
python -c "import pydantic.utils; print(pydantic.utils.version_info())
):3.1.1
Docker python:3.10-buster
Additional context
In my DB i have a collection "instruction" with objects like:
And I've added the index:
When I try to use the Find on Mongo Atlas, if I add this on the search field:
It returns the object correctly.
Also, if I change the python code to this:
Then the search works.
Is the find functionality not working fine or I'm just using it wrong?