Laravel 5 + MongoDB

6

我希望你能在 Laravel 5 中使用 MongoDB,使用 Laravel MongoDB。已经安装了 MongoDB PHP 驱动程序。与 MongoDB 相关的任何操作都返回 500 错误。

例如:

ExampleModel:

use Jenssegers\Mongodb\Model as Eloquent;
class ExampleModel extends Eloquent {
   protected $connection = 'mongodb';
   protected $collection = 'polls';
}

ExampleModelController:

<?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';
   }

}

Route to test in ExampleModelController works good.

Route::get('test', 'ExampleModelController@test');

This code returns error 500 (testing in Postman Chrome extension).

I used MongoDB with another project (with node.js) and everything works good, so MongoDB installed properly.

Any idea 'bout this problem?

P.S. No logs in storage/logs/ about this error.

OS: Mac OS X 10.10.2


这是我的失误。使用db.createUser()(而不是addUser)解决了对needle数据库的问题。 - Andrew Paramoshkin
请将解决问题的解决方案发布为答案并接受它,这样问题就不会出现为未解决的状态。谢谢。 - Charlotte Dunois
@CharlotteDunois 已完成,感谢建议 ) - Andrew Paramoshkin
1个回答

5
这是我的失误。问题已经解决。
db.createUser({user: "username", pwd: "secret", roles: ["readWrite"]})

在Mongo控制台中
使用NOT addUser方法


由于addUser方法已被弃用,即使在Mongo shell中运行此命令,它也会要求您使用createUser方法。 - Gaurav Dave

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接