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

Phalcon MongoDB count() with parameters does not work

Hi to all,

I notice that MongoDB ODM count does not work with parameters. You can read it here: https://docs.phalcon.io/en/latest/reference/odm.html

You see, regardless of the parameter I set, say,

array('field'=>'value_to_check')

It will disregard that and give the complete list instead.

My question is, am I doing it wrong? Because the documentation doesn't tell much, quite honestly, which needs to improve. If I am not doing it wrong, then what went wrong? The code is pretty much like this:

CollectionModel::count(array('field'=>'value_to_check'));

Looking forward for some clarifications.

Thanks a lot,

edited May '16

Hi.

In ODM your code must be something like this:

CollectionModel::count([ 'conditions' => [ 'field' => 'value_to_check ] ]);



9.5k

Thanks for the reply.

I have not continued to use this one though, instead, I used MongoCollection of PHP primarily because the table being referenced is not definite. There's a count method with it as well so I used it instead.

Alternatively, for such the same case I have noted above, a command using execute() under Mongo seems to work as well.

Still, I appreciate for giving time to reply regarding my question. Thanks a lot!