Skip to content
This repository has been archived by the owner on Jun 11, 2021. It is now read-only.

Can't connect to mongodb with Zend framework 1.12 #113

Open
ghost opened this issue Apr 11, 2013 · 9 comments
Open

Can't connect to mongodb with Zend framework 1.12 #113

ghost opened this issue Apr 11, 2013 · 9 comments

Comments

@ghost
Copy link

ghost commented Apr 11, 2013

I don't know how to connect with Mongodb in Zend Framework althought I done exactly the tutorial. Please help me.

This is my boostrap file.

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initDb()
{
//Setup mongo
$connection = new Shanty_Mongo_Connection("mongodb://admin:123456@localhost:27017");
$connection->setSlaveOkay(true);
Shanty_Mongo::addConnection($connection);
}

}

And this is what I got on my brwoser.
Untitled

@tholder
Copy link
Collaborator

tholder commented Apr 11, 2013

Hey,

My bootstrap looks like:

    protected function _initDb() {

        $config = Zend_Registry::get('config');

        //Setup mongo
        $connection = new Shanty_Mongo_Connection($config->mongo);
        Shanty_Mongo::addMaster($connection);

        Model_Mongo_Base::setDatabase($config->database);
    }

Then, in my config I simply have:

mongodb://localhost:27017
contactzilla

@ghost
Copy link
Author

ghost commented Apr 11, 2013

Thank you very much.

Can’t you send your config file to me?

Thanks.

Sent from Windows Mail

From: Tom Holder
Sent: ‎Thursday‎, ‎April‎ ‎11‎, ‎2013 ‎4‎:‎23‎ ‎PM
To: coen-hyde/Shanty-Mongo
Cc: Kevin1990

Hey,

My bootstrap looks like:

protected function _initDb() {

    $config = Zend_Registry::get('config');

    //Setup mongo
    $connection = new Shanty_Mongo_Connection($config->mongo);
    Shanty_Mongo::addMaster($connection);

    Model_Mongo_Base::setDatabase($config->database);
}

Then, in my config I simply have:

mongodb://localhost:27017
contactzilla


Reply to this email directly or view it on GitHub.

@tholder
Copy link
Collaborator

tholder commented Apr 11, 2013

Hi Kevin,

Not really it's got too much sensitive stuff in.

Sorry that didn't post right though, it's just literally two config elements mongo (the connection string) and database (the database)

@ghost
Copy link
Author

ghost commented Apr 11, 2013

Hi Tom,

Thank you, can you tell me $config->database, what does it mean? Is it database's name?

@ghost
Copy link
Author

ghost commented Apr 11, 2013

Hi Tom,

And what is Model_Mongo_Base class, I can't find in Shanty folder?

Please show me where is it. Thank you

@tholder
Copy link
Collaborator

tholder commented Apr 11, 2013

Hi Kevin,

Sorry that's just a base class I inherit all my mongo doc classes from to give some shared functionality.

class Model_Mongo_Base extends Shanty_Mongo_Document {

    protected static $_db = 'contactzilla';

    public static function setDatabase($db) {
        self::$_db = $db;
    }

@ghost
Copy link
Author

ghost commented Apr 11, 2013

Hi Tom,

Thanks a lot. It's worked. But When I call a model class it's give me the same error. I don't know what happen. Please help me.

This is my Model.

class Admin_Model_Post extends Shanty_Mongo_Document
{
protected static $_db = 'blog';
protected static $_collection = 'blog';
}

This is my Controller.

class Admin_IndexController extends Zend_Controller_Action
{
public function indexAction()
{
$posts = new Admin_Model_Post();
}

}

Do I need to run MongoDB service? I don't know why but my MongoDB service can't start.

But I still can connect to database using MongoVUE.

@tholder
Copy link
Collaborator

tholder commented Apr 11, 2013

This is the most basic you need:

class User extends Shanty_Mongo_Document 
{
    protected static $_db = 'forum';
    protected static $_collection = 'user';
}

If that won't connect you might well have a problem with your mongo setup.

@ghost
Copy link
Author

ghost commented Apr 11, 2013

I think the same as you, too.

I'll check again the mongo setup and then I will post the solution to help another one have the same problem to me.

Thank you very much, Tom.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant