Installed Mongo on my machine, and enabled Mongo/Mongo Cache/Mongo Field Storage (using this tutorial http://groups.drupal.org/node/183279). When I use drush, I get this error everytime:

Fatal error: Class 'Mongo' not found

When I comment out the cache settings in settings.php, drush works. How can I work around this and still use Mongo Cache?

Comments

fgm’s picture

Title: Fatal error: Class 'Mongo' not found - using drush » Implement Mongodb extension check for the cache plugin, not just in mongodb_requirements().

It looks like you did not enable the mongodb extension in PHP, which is not automatic when you install mongodb itself.

The module should catch the missing extension, though. It already checks for its presence in hook_requirements() but cache plugins run without a hook_requirements() check. Adjusting issue title accordingly

kevinquillen’s picture

Weird, I have extension=mongo.so in my php.ini, and see it enabled in phpinfo.

kevinquillen’s picture

Let me clarify, I can create nodes and fields and see them appear in my mongo database. Its when I try to use Mongo Cache module that drush breaks.

misc’s picture

Which settings are you using for the MongoDB cache in settings.php?

kevinquillen’s picture

settings.php:

$conf['mongodb_connections'] = array(
 'default' => array(                             // Connection name/alias
   'host' => 'localhost',                       // Omit USER:PASS@ if Mongo isn't configured to use authentication.
   'db' => 'newmongo'                   // Database name. Make something up, mongodb will automatically create the database.
  ),
);

include_once('./includes/cache.inc');

# -- Configure Cache
$conf['cache_backends'][] = 'sites/all/modules/mongodb/mongodb_cache/mongodb_cache.inc';
$conf['cache_class_cache'] = 'DrupalMongoDBCache';
$conf['cache_class_cache_bootstrap'] = 'DrupalMongoDBCache';
$conf['cache_default_class'] = 'DrupalMongoDBCache';

# Field Storage
$conf['field_storage_default'] = 'mongodb_field_storage';

# -- Don't touch SQL if in Cache
$conf['page_cache_without_database'] = TRUE;
$conf['page_cache_invoke_hooks'] = FALSE;

misc’s picture

cache_backends does not work for me either (see http://drupal.org/node/1413178), add:

include_once('./sites/all/modules/mongodb/mongodb_cache/mongodb_cache.inc');

(If you mongodb is in the sites all...)

EDIT: sorry, removed #...

misc’s picture

@Kevin Quillen see: #1514556: Example settings for cache in README.txt does not work

You should remove:

include_once('./includes/cache.inc');

And:

$conf['cache_class_cache'] = 'DrupalMongoDBCache';
$conf['cache_class_cache_bootstrap'] = 'DrupalMongoDBCache';

To get

$conf['cache_backends'][] = 'sites/all/modules/mongodb/mongodb_cache/mongodb_cache.inc';

To work.

misc’s picture

Title: Implement Mongodb extension check for the cache plugin, not just in mongodb_requirements(). » Fatal error: Class 'Mongo' not found - using drush

Changed back the title, because of the error is not missing mongodb extension (but we need a check for that, started work for that in #1514698: Check requirements for Mongodb cache)

misc’s picture

@Kevin Quillen did it work for you?

misc’s picture

Status: Active » Postponed (maintainer needs more info)
misc’s picture

Status: Postponed (maintainer needs more info) » Fixed

Marked is fixed in lack of response.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

pwaterz’s picture

Status: Closed (fixed) » Active

I am also getting this error. I greped the code for 'class Mongo' and found nothing. On line 32 of mongodb.module you call $mongo = new Mongo($host);

pwaterz’s picture

Status: Active » Closed (fixed)

Ahh I just realized that is supposed to come from the php extension. AHHH...I am missing extension=mongo.so in my php cli php.ini

pwaterz’s picture

This is really off topic, but the install.txt for this module could use some work.

misc’s picture

@pwaterz, have you checked the README.txt in the latest dev?

Anonymous’s picture

Version: 7.x-1.0-beta2 » 7.x-1.0-rc1
Status: Closed (fixed) » Active

Hi, I keep getting this issue when trying to run 'drush mongodb-migrate-prepare'.

Error: Class 'Mongo' not found in mongodb.module line 34

Running drush on Windows 7 from the drush installer for windows. I run drush in the root of my drupal site.

MongoDB PHP is loaded, working and seen in phpinfo().

But for some reason, running drush does not load the mongodb php?

Could it be 32bit / 64bit conflict? My PHP/mongo is 64 bit, but I think drush-for-windows is 32 bit?

fgm’s picture

More likely you are not using the same php.ini for drush (CLI SAPI) and web (on Windows, probably ISAPI or FASTCGI SAPI): if your php.ini for CLI does not load mongo.so that makes sense.

Can you check "php -i" from the command line to see if the Mongo is loaded ?

Anonymous’s picture

Status: Active » Closed (fixed)

PHP CLI of course. Drush for windows has its own PHP with php.ini

fgm’s picture

That's a good start: but does that php.ini load the Mongo extension ?

On Debian, all php.ini default to loading from the conf.d directory and there's a mongo.conf there, so the extension is always loaded whatever the SAPI. But maybe this is different on Windows ? When you run php -i, do you see the mongo extension listed ?

couloir007’s picture

I'm running Ubuntu and was getting this error trying to drush cc all. I did this:

sudo ln -s /etc/php5/mods-available/mongo.ini /etc/php5/cli/conf.d/mongo.ini

and now all is well.