Mongodb + Cakephp2.x Class Mongo not found

I’m trying to connect Mongodb to Cakephp2.x .
Followed ichikaway’s github tutorial: , but it shows the following code:

Fatal Error

Error: Class ‘Mongo’ not found
File: /var/www/html/cakephp/lib/Cake/Model/ConnectionManager.php
Line: 112

You might want to link to the tutorial in question, not everyone is familiar with it. :slight_smile:

Added the tutorial :+1:

What does your DATABASE_CONFIG look like? The documentation there says you should use 'datasource' => 'Mongodb.MongodbSource', but your error references a class just called Mongo.

My databse.php looks like this:


public $default = array(
‘datasource’ => ‘Mongodb.MongodbSource’,
‘host’ => ‘localhost’,
‘database’ => ‘cakemongo1’,
‘port’ => 27017,
‘prefix’ => ‘’,
‘persistent’ => ‘true’


Exactly what version of Cake are you using? Line 112 of ConnectionManager.php is a comment in the latest version, and that file hasn’t been changed in 3 years.

My version is:
Welcome to CakePHP v2.10.20 Console

2.10.20 appears the be the current version of the 2.x branch. Is your version edited from that? Again, line 112 of ConnectionManager.php in that version is a comment, but you’re reporting an error from it, so something is different.

It’s not commented out in my ConnectionManager.php .
I tried to comment line 112 out, and then it errored the same message, but to line 111. Then, if I comment that out it, it calls the following:

[ Notice (8)](javascript:void(0);): Undefined index: default [ CORE/Cake/Model/ConnectionManager.php , line 114 ]

It’s not “commented out”, it’s part of a block comment. See here. How does this line up with that you have?

Oh okay, I understand.

I used the code that you sent and it still errors out and points to the same block of code. Instead, it’s line 105 from the code you sent. This is the line:

105 static::$_dataSources[$name] = new $class(static::$config->{name}); 106 static::_dataSources[$name]->configKeyName = name; 107 108 return static::_dataSources[$name];

I don’t have a 2.x install that I can test anything with, and I don’t have a Mongo database anyway, so I’m about at the end of what I can do here. It concerns me somewhat that you say you’ve got the latest version of Cake 2.x, but the code doesn’t match what’s in the git repo. If that’s the case for this file, might it also be true for others? And might one of those mystery edits somehow be responsible for the issue? Could be that the problem is entirely local to your particular installation in that case.

Beyond that, the plugin says it’s for Cake 2.2.5 or higher, but it’s possible that something changed in Cake between 2.2.5 and 2.10.20 that has rendered it broken. It does say it’s abandoned, but no indication of whether it was abandoned mid-2.x, or it’s just not going to be updated to 3.x.