Closed pirmax closed 4 years ago
same problem
@pirmax and @n0n0n0n0 did you have any luck with finding solution for this problem...?
same problem
same problem
I found a solution. This error occurs because the connection name -- inside the moloquent database config -- is missing. Actually, laravel puts the connection name automatic, but moloquent doesn't. When the connection name is not found, laravel uses the default connection configured in the file /config/database.php, in most cases it is the mysql.
You can solve this by two ways:
Add connection name into mongodb config :
'mongodb' => [
'driver' => 'mongodb',
'host' => env('MONGODB_HOST', 'localhost'),
'port' => env('MONGODB_PORT', 27017),
'database' => env('MONGODB_DATABASE'),
'username' => env('MONGODB_USERNAME'),
'password' => env('MONGODB_PASSWORD'),
'name' => 'mongodb'
]
Overwrite the moloquent provider to fix it. ( best in my opnion )
<?php
namespace App\Providers;
use Moloquent\MongodbServiceProvider as Base;
use Moloquent\Queue\MongoConnector;
class MongodbServiceProvider extends Base{
public function register()
{
// Add database driver.
$this->app->resolving('db', function ($db) {
$db->extend('mongodb', function ($config, $name) {
$config['name'] = $name;
return new \Moloquent\Connection($config);
});
});
// Add connector for queue support.
$this->app->resolving('queue', function ($queue) {
$queue->addConnector('mongodb', function () {
return new MongoConnector($this->app['db']);
});
});
}
}
/config/app.php
// Moloquent\MongodbServiceProvider::class, App\Providers\MongodbServiceProvider::class,
I have this error with moloquent/moloquent package.
composer require moloquent/moloquent
My Item class Model extended from Moloquent:
My test to insert into items collection:
Result: