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 ISODate not working

I'm facing trouble querying mongodb with date ranges. These dates are stored in the database using date type.

Collection::find(array("timestamp" => 'ISODate("2015-11-05T15:19:21+00:00")' ));
Collection:find(array("timestamp" => '2015-11-05T15:19:21+00:00' ));

These two queries return all 1000 documents spanning about a month, not just a day.

Collection::find(array("timestamp" => new MongoDate(strtotime(date('Y-m-d 00:00:00'))) ));

Again returning all month documents

Collection::find(array("timestamp" => ISODate("2015-11-05T15:19:21+00:00") ));

Call to undefined function ISODate

What do I do to accurately query documents for a day?

Hey, have you debugged your query to see the actual query send to mongodb?

Also check the examples in the docs here: https://docs.phalcon.io/en/latest/reference/odm.html#finding-documents

// All virtual robots ordered by name downward
$robots = Robots::find(
    array(
        "conditions" => array("type" => "virtual"),
        "sort"       => array("name" => -1)
    )
);