Everything worked fine when I used as a connection string: mongodb://0.0.0.0:27017/data
. After add Enable Access Control with connection string: mongodb://user:pwd@0.0.0.0:27017/?authSource=data
stops working.
I'm connected to mongodb but in application I see on request This request has no response data available
. But for connection string to mongodb://0.0.0.0:27017/data
there was data.
To add authentication I used this instruction Enable Access Control:
I created admin:
> use admin
switched to db admin
> db.createUser(
... {
... user: 'admin',
... pwd: 'password',
... roles: [ { role: 'root', db: 'admin' } ]
... }
... );
Successfully added user: {
"user" : "admin",
"roles" : [
{
"role" : "root",
"db" : "admin"
}
]
}
> exit;
I changed mongo config file - mongod.cfg:
security:
authorization: enabled
I logged in as admin:
> use admin
> db.auth('admin','password');
1
I created new user:
use data
db.createUser(
{
user: "user",
pwd: "pwd",
roles: [
{ role: "dbAdmin", db: "data" },
]
}
)
db.grantRolesToUser(
"user",
[ "readWrite" , { role: "read", db: "data" } ],
{ w: "majority" , wtimeout: 4000 }
)
And I used: mongodb://user:pwd@0.0.0.0:27017/?authSource=data
as a connection string, but there is not working. What am I doing wrong?