我在使用Laravel MongoDB的Laravel 5中使用MongoDB时遇到问题。已安装MongoDB PHP驱动程序。任何使用MongoDB的操作都会返回500错误。我的例子:
示例模型:
use Jenssegers'Mongodb'Model as Eloquent;
class ExampleModel extends Eloquent {
protected $connection = 'mongodb';
protected $collection = 'polls';
}
示例模型控制器:
<?php namespace App'Http'Controllers;
use App'Http'Requests;
use App'Http'Controllers'Controller;
use App'ExampleModel;
use Illuminate'Http'Request;
class ExampleModelController extends Controller {
public function test()
{
$test = new ExampleModel();
$test->create(["foo" => "bar"]);
return 'ok';
}
}
在ExampleModelController中进行测试的路径运行良好。
Route::get('test', 'ExampleModelController@test');
此代码返回错误500(在Postman Chrome扩展中测试)。
我在另一个项目(使用node.js)中使用了MongoDB,一切都很好,所以MongoDB安装正确。
你知道这个问题吗?
附言:存储区/logs/中没有关于此错误的日志。
操作系统:Mac OS X 10.10.2
那是我的秋天。解决了问题
db.createUser({user: "username", pwd: "secret", roles: ["readWrite"]})
在mongo控制台中
NOT addUser方法