Pushparaj Yuvaraj
Pushparaj Yuvaraj

Reputation: 11

How to connect Mongodb with Yii2

This is what I have in common/config/main-local:

'mongodb' => [
    'class' => 'yii\mongodb\Connection',
    'dns' => 'mongodb://localhost:27017/test',
],

What's wrong with that?

Upvotes: 0

Views: 524

Answers (2)

Sunny Gohil
Sunny Gohil

Reputation: 235

Replace "localhost" to "127.0.0.1"

'mongodb' => [
        'class' => '\yii\mongodb\Connection',
        'dsn' => 'mongodb://127.0.0.1:27017/test',
    ],

Upvotes: 3

WhiteViking
WhiteViking

Reputation: 3201

There's a typo. It should be

'dsn' => 'mongodb://localhost:27017/test'

instead of

'dns' => 'mongodb://localhost:27017/test'

Upvotes: 0

Related Questions