Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
MongoDb
  • Can some on tell me how to config, select collections and use MongodDb with FuelPhp?
  • Ok, so I made a little progress and even it still not working right now, here is what I came up with: 1. I found configuration Array for redis in conf/db.php and the __construct() function in mongodb Class.
    So I edited it a little: 'mongo' => array(
    'default' => array(
    'hostname' => '127.0.0.1',
    // 'persistent' => '',
    'database' => 'test',
    // 'username' => '',
    // 'password' => '',
    'port' => 27017,
    )
    ), Now, when I try to instantiate Redis, it working as expected.
    $redis = Redis::instance('test'); --> an error in the Redis Class (because I have no Redis installed) But when I try to do exactly the same to access Mongo, it throws:
    Call to undefined method MongoDB::instance() I looked in to the bootstrap and MongoDb is in there. So how can it be? What am I doing wrong, any suggestions?
  • Watch your case. The class is defined as 'MongoDb', so you should use MongoDb::instance();.
  • Guess what, this is exactly what I did: ;)
    ErrorException [ Error ]: Call to undefined method MongoDB::instance() 
    
    APPPATH/classes/controller/welcome.php @ line 23
    
    18     * @return  void
    19     */
    20    public function action_index()
    21   
    22    //    echo Debug::classes();    
    23    $m = MongoDb::instance('test');
    24    //    $redis = Redis::instance('mystore');
    25    //    $this->response->body = View::factory('welcome/index');
    26    }
    
    Which is strange, because the Debug lists the existence of this classes:
    echo Debug::classes()
    
    "Mongo"
    "MongoDB"
    "MongoCollection"
    "MongoCursor"
    "MongoGridFS"
    "MongoGridFSFile"
    "MongoGridFSCursor"
    "MongoId"
    "MongoCode"
    "MongoRegex"
    "MongoDate"
    "MongoBinData"
    "MongoDBRef"
    "MongoException"
    "MongoCursorException"
    "MongoCursorTimeoutException"
    "MongoConnectionException"
    "MongoGridFSException"
    "MongoTimestamp"
    "MongoInt32"
    "MongoInt64"
    "MongoMaxKey"
    "MongoMinKey"
    
    Ps: I'm using a clean install of rc3, where only db.php and Welcome controller are edited.
  • Since you're using RC3, you could be suffering from a bug that has been fixed in development, because you're dump (and the error message) mentions MongoDB, not MongoDb. Check fuel/core/bootstrap, and change MongoDB to MongoDb. This has been corrected in the develop branch.
  • Well it was not so obvious to me, also because in the MongoDb Class there was this inconsistency everywhere. (exceptions messages/code) I think I'll stick with the plain php mongodb driver for the moment and refactor it latter, when this feature is more stable. (Didn't got it to work with the develop and mongo-feature branches)
    And yes, I am not very experienced with fuelphp, but you seems to be an truthful evangelist =)
    Thanks anyway.
  • Odd, since it works here on a fresh clone of develop...

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion