Bounty available!

It has been a while and this question still does not have any answers. Answer this question and get additional +208 points of karma/reputation if the original poster accepts your reply as correct answer

MongoDB - problem finding by geolocation does not work

Hi,

I try the code below in PHP in order to get two results, but it returns all results. I tested this query in mongo and it works, just in the PHP it does not work. I use the incubator library and PHP 7.1.

$query = ['location' => 
    ['$near' => 
        ['$geometry' => 
            ['type' => "Point", 
            'coordinates' => [-23.9768691, -46.194405]], 
            '$minDistance' => 0, 
            '$maxDistance' => 5000]
        ]
    ];

$events = Events::find($query);

I don't know what's the problem. I did not have problems finding by text, and others. I have tried to query direct with the MongoClient object, but no success too.

Thanks,

Wow... It looks that writing about the problem I could solve it. Now it works:

$events = Events::find([$query]);

Encapsulating the query array inside an array... It was missing... Posting here in case it helps someone in the future...