We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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...