cakephp mongodb:注意(1024):连接到localhost:27017失败:mongodb_source.php中的未知错误

时间:2011-11-18 07:06:32

标签: cakephp mongodb

运行我的网站时出现以下错误:

Notice (1024):connecting to localhost:27017 failed: Unknown error [APP\plugins\Mongodb\models\datasources\mongodb_source.php, line 201]Code | Context        } catch(MongoException $e) {
            $this->error = $e->getMessage();
            trigger_error($this->error);$host   =   "localhost:27017"
$e  =   MongoConnectionException
MongodbSource::connect() - APP\plugins\Mongodb\models\datasources\mongodb_source.php, line 201
MongodbSource::isConnected() - APP\plugins\Mongodb\models\datasources\mongodb_source.php, line 251
MongodbSource::read() - APP\plugins\Mongodb\models\datasources\mongodb_source.php, line 876
Model::find() - CORE\cake\libs\model\model.php, line 2130
MotorDevelopmentsController::search() - APP\controllers\motor_developments_controller.php, line 13
Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 204
Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 171
[main] - APP\webroot\index.php, line 87

谁能说出我做错了什么?谢谢。

我已经为https://github.com/ichikaway的cakephp放置了Mongodb数据库驱动程序(版本0.4) 在\ merry_flowers \ plugins中。我把它改名为Mongodb(camelized)。

\ merry_flowers \ config \ database.php

    <?php
     class DATABASE_CONFIG {

var $default = array(
    'driver' => 'mysql',
    'persistent' => false,
    'host' => 'localhost',
    'login' => 'root',
    'password' => 'pass',
    'database' => 'merry_flowers_db',
);

public $mongo = array(
    'driver' => 'mongodb.mongodbSource',
    'database' => 'student_db',
    'host' => 'localhost',
    'port' => 27017

);  

  }
      ?>

我正在为我的网站使用mysql数据库(用于所有内容)和mongodb(仅用于报告目的)。

模型中的

:motor_development.php

    <?php
class MotorDevelopment extends AppModel {
    var $name ='MotorDevelopment';
    //var $primaryKey ='student_id';
    var $useDbConfig='mongo';
    //var $useTable=false;
    var $mongoSchema=array(
                            'student_id'=>array('type'=>'integer','primary'=>true,'length'=>10),
                            'Draws freehand pictures'=>array('type'=>'string','length'=>1),
                            'Cuts and paste pictures'=>array('type'=>'string','length'=>1)
                            );

}


?>

merry_parents_controller.php

  .....
  $this->redirect(array('controller'=>'motor_developments', 'action'=>'search',$student_info));

controller:motor_developments_controller.php

      <?php
class MotorDevelopmentsController extends appController{
    //public $MotorDevelopment;
    public $name='MotorDevelopments';

    public function search(){
        echo 'SEARCH';
        var_dump($student_info);
        $x=$this->MotorDevelopment->find('one',array('conditions'=>array('MotorDevelopment.student_id'=>12)));
        $this->set('x',$x);
        $this->set(compact('x'));
    }
}
?>

Mongodb数据库详细信息:

mongodb database name: student_db
collection: motor_developments
the record i have inserted:
         student_id:12
         Draws freehand pictures:B
         Cuts and pastes pictures:B

1 个答案:

答案 0 :(得分:1)

我有很多困难让它发挥作用,但我终于做到了!我使用最新的CakePHP版本创建了一个带有MongoDB数据源的简单模板的github仓库:

https://github.com/marcferna/CakePHP-MongoDB-Template

如果您下载此模板但它不起作用,那么在您的localhost中运行的MongoDB服务器将会出现问题。

希望你能使它发挥作用。