Pablo Santamaria
Pablo Santamaria

Reputation: 767

How to use MongoDB with Kohana 3.3? using MangoDB

I'm trying to use MongoDB with Kohana using MangoDB. I've downloaded MangoDB which is a library to use MongoDB with Kohana https://github.com/Wouterrr/MangoDB

I know some of the questions here are very basic, but I need to ask because I couldn't find any documentation for MangoDB.

First, I don't know where to copy/paste the downloaded library. Second, can I define the database at modules/database/config/database.php, probably something like:

...
'default' = array
(
   'type'   => 'mongodb',
   'connection' => array(
      'hostname' => 'no idea what to put here'
      'database' => 'example'
      'username' => 'no idea what to put here'
      'password' => 'no idea what to put here'
      'persistent' => 'no idea what to put here'
   ),
...

Third, what should I change at application/bootstrap.php, should I change anything there? Or what should I do exactly.

...
kohana::modules(array(
   'database' => MODPATH.'database',
   'orm' => MODPATH.'orm',
...

I would really appreciate any help or guidance to get started with this.

A similar question was asked before here: How can I use MongoDB in Kohana? and the best answer suggested not using MangoDB at all. But I think it is important to use an ORM/Active Record like library because it makes it easier to change the database in the future.

Upvotes: 1

Views: 273

Answers (1)

Daan
Daan

Reputation: 7925

It's good to know how Kohana's cascading file system and Kohana modules work. Basically when you have the same folder structure in application, modules and system than application overwrites modules and modules overwrites system. You should only write your own code in application.

Put the MonogDB module in a dir called mangodb in the modules directory. So you should have some paths like this: modules/mangodb/config and modules/mangodb/classes.

Do not define anything in modules/database/config/database.php, instead copy and rename this file to application/config/database.php. Because the array key name is "default", you application should now use this file. Of course, change the config parameters to work with your own database.

Don't forget to enable the module in your bootstrap.php, I added the last module mangodb in this piece of code:

Kohana::modules(array(
    'auth'       => MODPATH.'auth',       // Basic authentication
    'cache'      => MODPATH.'cache',      // Caching with multiple backends
    'codebench'  => MODPATH.'codebench',  // Benchmarking tool
    'database'   => MODPATH.'database',   // Database access
    'image'      => MODPATH.'image',      // Image manipulation
    'orm'        => MODPATH.'orm',        // Object Relationship Mapping
    'oauth'      => MODPATH.'oauth',      // OAuth authentication
    'pagination' => MODPATH.'pagination', // Paging of results
    'unittest'   => MODPATH.'unittest',   // Unit testing
    'mangodb'  => MODPATH.'mangodb',  
    ));

Upvotes: 1

Related Questions