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 ODM

Does anybody use Phalcon with Mongo? What libraries: stock component or other 3rd party? Advantages / disadvantages / wishes?

I am use Phalcon with Mongo. Phalcon ODM using PHP MongoClient. There are all you need. Additionaly "rockmongo" for working with mongo as phpmyadmin.

One limitation to keep in mind is that, as of 1.2.4, there is no direct way to remove multiple documents at the same time via the ODM. You either get the list of documents, then delete them one by one, or get the native collection and do a remove from that with something like:

$products = new Products();
$collection = $products->getConnection()->selectCollection($products->getSource());
$collection->remove(array('your' => 'criteria'));

There is an NFR in the Github issues to address this, but it's unknown when it will come about. As the framework matures, you will also probably have to change up some of the class declarations as the framework is currently written explicitly for Mongo and will have to be refactored a bit if they want to support other NoSQL solutions with the ODM (things like setId() return a MongoId object, etc).

@Oleksandr Torosh, @Mark Garrett yeah, you are both right. But there is always a "but" ... Phalcon ODM looks a bit limited to my tasks: no embedded documents support, no schema / mapping / type casting, no support for schema migrations. In several projects I am involved with we decided to give MongoDB a go, but I cannot find a suitable library / framework to use. They all either outdated / badly supported / not PSR compliant or simply monstrous, e.g., Doctrine ODM. You reckon it is bad idea to build my own one or should I expect that stock library will improve ... some time in the feature ... when they have a time for it ... and wish ... and demand ??