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

Mongo ODM, cannot run two queries on the same collection

Hi guys,

I have a collection:

class Keyword extends Collection

{

public function initialize()
{
    $this->setSource('keywords');
}

}

I have two calls in the same function:

Keyword::count($query)

Keyword:find($anotherQuery)

I always get only one correct result, the find call returns an empty array, but when I comment out the first call I receive an array of items, the same problem with two ::find calls, instead of ::count

edited May '16

I've found the problem, this is the mongodb log:

2016-05-04 10:23:28.925 COUNT [keywords] : []

2016-05-04 10:23:28.925 QUERY [keyword] : {"$orderby": {"id": -1}, "$query": {}}

the second query tries to use "Keyword" not "Keywords" name of the collection, ignoring $this->setSource("keywords")

any ideas how to solve it?

edited May '16

Solved with:

public function getSource() { return 'keywords'; }

removed initialize()

Thanks it was really useful

Solved with:

public function getSource() { return 'keywords'; }

removed initialize()

Thanks for saving my day, I encountered with this and have no idea what's wrong. It's been 3 years and Phalcon hasn't even fixed this, I can see how hard open source it is!