# Mongodb + Cakephp2.x Class Mongo not found

**URL:** <https://discourse.cakephp.org/t/mongodb-cakephp2-x-class-mongo-not-found/7791>\
**Category:** Need Help\
**Created:** [May 6, 2020, 3:55pm UTC](https://discourse.cakephp.org/t/mongodb-cakephp2-x-class-mongo-not-found/7791 "2020-05-06T15:55:40Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ar999](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@Ar999](https://discourse.cakephp.org/u/Ar999)\
**Post date:** [May 6, 2020, 3:55pm UTC](https://discourse.cakephp.org/t/mongodb-cakephp2-x-class-mongo-not-found/7791/1 "2020-05-06T15:55:41Z")

</div>

I’m trying to connect Mongodb to Cakephp2.x .  
Followed ichikaway’s github tutorial: [https://github.com/ichikaway/cakephp-mongodb](https://github.com/ichikaway/cakephp-mongodb) , 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

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [May 6, 2020, 4:12pm UTC](https://discourse.cakephp.org/t/mongodb-cakephp2-x-class-mongo-not-found/7791/2 "2020-05-06T16:12:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ar999](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@Ar999](https://discourse.cakephp.org/u/Ar999)\
**Post date:** [May 6, 2020, 4:15pm UTC](https://discourse.cakephp.org/t/mongodb-cakephp2-x-class-mongo-not-found/7791/3 "2020-05-06T16:15:47Z")

</div>

Added the tutorial 👍

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [May 6, 2020, 4:51pm UTC](https://discourse.cakephp.org/t/mongodb-cakephp2-x-class-mongo-not-found/7791/4 "2020-05-06T16:51:22Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![Ar999](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@Ar999](https://discourse.cakephp.org/u/Ar999)\
**Post date:** [May 6, 2020, 4:59pm UTC](https://discourse.cakephp.org/t/mongodb-cakephp2-x-class-mongo-not-found/7791/5 "2020-05-06T16:59:20Z")

</div>

My databse.php looks like this:

CakePlugin::load(‘Mongodb’);

class DATABASE\_CONFIG {  
public $default = array(  
‘datasource’ =\> ‘Mongodb.MongodbSource’,  
‘host’ =\> ‘localhost’,  
‘database’ =\> ‘cakemongo1’,  
‘port’ =\> 27017,  
‘prefix’ =\> ‘’,  
‘persistent’ =\> ‘true’  
);

}

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [May 6, 2020, 5:39pm UTC](https://discourse.cakephp.org/t/mongodb-cakephp2-x-class-mongo-not-found/7791/6 "2020-05-06T17:39:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ar999](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@Ar999](https://discourse.cakephp.org/u/Ar999)\
**Post date:** [May 6, 2020, 6:39pm UTC](https://discourse.cakephp.org/t/mongodb-cakephp2-x-class-mongo-not-found/7791/7 "2020-05-06T18:39:32Z")

</div>

My version is:  
Welcome to CakePHP v2.10.20 Console

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [May 6, 2020, 6:44pm UTC](https://discourse.cakephp.org/t/mongodb-cakephp2-x-class-mongo-not-found/7791/8 "2020-05-06T18:44:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ar999](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@Ar999](https://discourse.cakephp.org/u/Ar999)\
**Post date:** [May 6, 2020, 7:03pm UTC](https://discourse.cakephp.org/t/mongodb-cakephp2-x-class-mongo-not-found/7791/9 "2020-05-06T19:03:04Z")

</div>

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**]

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [May 6, 2020, 7:46pm UTC](https://discourse.cakephp.org/t/mongodb-cakephp2-x-class-mongo-not-found/7791/10 "2020-05-06T19:46:49Z")

</div>

It’s not “commented out”, it’s part of a block comment. See [here](https://github.com/cakephp/cakephp/blob/2.x/lib/Cake/Model/ConnectionManager.php#L112). How does this line up with that you have?

---

<div class="post-metadata">

**Author:** ![Ar999](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@Ar999](https://discourse.cakephp.org/u/Ar999)\
**Post date:** [May 6, 2020, 8:10pm UTC](https://discourse.cakephp.org/t/mongodb-cakephp2-x-class-mongo-not-found/7791/11 "2020-05-06T20:10:59Z")

</div>

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];

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [May 6, 2020, 8:31pm UTC](https://discourse.cakephp.org/t/mongodb-cakephp2-x-class-mongo-not-found/7791/12 "2020-05-06T20:31:58Z")

</div>

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.
