Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Help setting up MongoDB

I could do with a little help setting up mongoDB with Phalcon to output a simple find

The system I have is as follows:

  • ubuntu 17.04
  • php 7.022
  • Phalcon v3.2.2

(New 'MongoDB' not old 'Mongo' type)

  • MongoDB Server V3.4.7
  • MongoDB extension v1.2.10 (stable)
  • MongoDB Driver (I think v1.2 via composer)
  • New install of Incubator via composer

I can use the php driver to get the result I need but I cannot do it the phalcon way.

I have tried for over a week to get anything to work, spent hours on google reading old and new posts about getting MongoDB to work and have completely destroyed numerous VM installations in the process.

To make things really simple and easy to understand what is needed, and what is happening a simple test script without models and controllers just the absolute basics needed for it to work would be a great help from anyone.

It appears I am not the only one with this issue and I would rather not use the old deprecated extension when it sounds like some have got the new Mongodb extension working ok.



use or include needed files/classes

connect to MongoDB at

connect to 'machinesdb'

connect to robotsCollection

$result = robotsCollection::find()


edited Sep '17

You'd have to use Phalcon incubator ATM, as there's no full support for new MongoDB extension in official PhalconPHP yet :/


For anyone still struggling to get with php 7 and phalcon 3.22 working .... in a test enviroment Create this file and save as index.php (it only serves to prove that everything is setup properly for a new installation.

using composer... for ubuntu users run from commmand line

composer require phalcon/incubator:^3.2

check if "mongoDB" is loaded properly using phpinfo(). If it is not loaded code below will show

Error Class "MongoDB\Driver\Manager" not found'

//ensure errors are displayed
ini_set('display_errors', 1);
error_reporting(E_ALL ^ E_NOTICE);

// phpinfo(); // uncomment to check 


$mongoClient = new \Phalcon\Db\Adapter\MongoDB\Client("mongodb://");
$mongodb = $mongoClient->selectDatabase("test");

echo "<pre>";

if it all works properly and phalconphp connects to MongoDB it will simply output the connection object which includes the database name it is connected to