Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 + MongoDB

I have a problem with using MongoDB in Laravel 5 using Laravel MongoDB. MongoDB PHP driver installed. Any operations with MongoDB returns 500 error. My example:

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

like image 966
Andrew Paramoshkin Avatar asked Apr 06 '15 12:04

Andrew Paramoshkin


1 Answers

It was my fall. Problem solved with

db.createUser({user: "username", pwd: "secret", roles: ["readWrite"]})

in mongo console
NOT addUser method

like image 50
Andrew Paramoshkin Avatar answered Oct 30 '22 12:10

Andrew Paramoshkin