在Laravel 5.2中,我正在尝试与mongodb连接 . 我已按照https://github.com/jenssegers/laravel-mongodb中提到的步骤进行操作 . 在运行命令'php artisan migrate'时在迁移中创建表后,出现错误
[MongoConnectionException] Failed to connect to: localhost:27017: Authentication failed on database 'admin' with username 'admin': auth failed
迁移文件看起来像这样,只是用工匠创建它:
<?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
)
),
使用的版本:
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"jenssegers/mongodb": "^2.2"
},
有人可以帮我解决这个问题