Mongodb authentication exception


(SomebodyHere) #1

I’m trying to connect to MongoDB, but I keep getting this error:

I’ve been searching through Stack Overflow, GitHub, etc. for days (this is literal) but I can’t find any similar situations. Most have to do with user/password authentication problems and I don’t even have that set up.

PHP driver:

  • PHP Version: 7.2.2
  • MongoDB Version: 4.0
  • MongoDB PHP Driver Version: 1.5.3
  • Yii2 MongoDB Extension Version: ~2.1.0

I’m not sure what’s going on because I have no username or password set up.
I can connect to MongoDB through Compass and Mongo Shell. I don’t know if it’s the PHP driver problem or the extension problem? It seems to be the querying that’s giving me a problem.

In my controller I have only:
$query = new Query();
$query->from(‘message’)->where([‘sender_id’ => 6]);
$rows = $query->all();

In frontend\config\main.php:
‘components’ => [
‘mongodb’ => [
‘class’ => ‘\yii\mongodb\Connection’,
‘dsn’ => ‘mongodb://@localhost:27017/dbname’,
],

(“Message” is a collection in the db I’m connecting to and I’ve already checked that the port is 27017 and the dbname is correct.)

In composer.json:
“require”: {
“php”: “>=5.4.0”,
“yiisoft/yii2”: “~2.0.6”,
“yiisoft/yii2-bootstrap”: “dev-master”,
“yiisoft/yii2-swiftmailer”: “~2.0.0 || ~2.1.0”,
“yiisoft/yii2-mongodb”: “~2.1.0”,
“yii2tech/embedded”: “*”,
“mongodb/mongodb”: “^1.5@dev”
},

In the Yii debugger I’m getting:

I don’t know if the rest of this is useful but I’ll put it up here anyway:

Would appreciate it if anyone could give me help. Thanks!


(SomebodyHere) #2

Nevermind, I figured out a solution, After I created a user role for my db and accessed it from there it worked. :smiley: