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

PHP 7.0 & Phalcon 3.0 & MongoDB\Driver\Manager

I've seen a few posts here and there, did my google search, and understand that from PHP 5.X to PHP 7.X the MongoDB API has changed. AFAIK, Phalcon does not yet support it? I am looking at starting a new project, and right now its not so much of an issue, rather than a question; will newer version of Phalcon support MongoDB? I am using the packagecloud.io Phalcon package, and using MongoDB\Driver\Manager hints that I won't be able to use Models at all?

i see source code .

https://github.com/phalcon/cphalcon/blob/master/phalcon/cache/backend/mongo.zep

i find a row code :

let mongo = new \MongoClient(server);

so, Phalcon does not support MongoDB extension.

You can write a custom mongodb driver



8.7k

Here is a quick guide to using the MongoDB with Phalcon 3.x

1) Download the Incubator. Instructions here: https://github.com/phalcon/incubator under "Autoloading from the Incubator".

2) Change your DI to use the new Mongo adapter

// shared mongo service 
$di->set('mongo', function() {

    $mongo = new \Phalcon\Db\Adapter\Mongo\Client("mongodb://127.0.0.1");
    return $mongo->selectDB('dbname');

}, true);

3) Change your Models to extend the new MongoCollection class

class SomeModel extends \Phalcon\Db\Mvc\MongoCollection

That should do it.