在Laravel 5.2中无法与mongodb连接

时间:2016-01-06 10:17:27

标签: mongodb laravel-5 laravel-5.2

在Laravel 5.2中,我正在尝试连接mongodb。我已按照https://github.com/jenssegers/laravel-mongodb中提到的步骤进行操作。在我运行命令' php artisan migrate'时在迁移中创建表后,我收到错误

[MongoConnectionException]
  无法连接到:localhost:27017:数据库' admin'上的身份验证失败使用用户名' admin':身份验证失败

Migration文件看起来像这样,只是用artisan创建它:

const ReactComp extends React.Component{
  render(){
    let styles = './postcss-bem.css'
    return <div class={styles.blockname}>something</div>
  }
}
<?php

 use Illuminate\Database\Schema\Blueprint;
 use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
  /**
   * Run the migrations.
   *
   * @return void
  */
public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string("username")->unique();
        $table->string("password");
        $table->timestamps();
    });
}

 /**
  * Reverse the migrations.
  *
  * @return void
  */
  public function down()
   {
       Schema::drop('users');
   }
}

使用的版本:

db config:

 'mongodb' => array(
        'driver'   => 'mongodb',
        'host'     => env('DB_HOST', 'localhost'),
        'port'     => env('DB_PORT', 27017),
        'database' => env('DB_DATABASE', '*****'),
        'username' => env('DB_USERNAME', 'admin'),
        'password' => env('DB_PASSWORD', 'admin'),
        'options' => array(
            'db' => env('DB_AUTH_DATABASE', '') // sets the authentication database required by mongo 3
        )
    ),

有人可以帮我解决这个问题吗

0 个答案:

没有答案