local Database
.The Problem is When I connect either with username and pass or without them the connections get established! and data are stored in both cases
I tried the steps below:
Mongodb Compass Shell
and CONNECT
use admin
db.dropAllUsers()
- to clean the users datadb.createUser(
{
user: "Admin",
pwd: "myNewPassword",
roles: [ { role: "userAdminAnyDatabase", db: "posts" } ]
}
)
-to create a username and password and assign a role (based on Mongodb Docs)
6. Disconnected from the database via GUI Menu bar (Connect Button > Disconnect)
7. Didn't find the /etc/mongod.conf
path so I managed to find a so-called file somewhere else(no idea if it is the right one):
C:\Program Files\MongoDB\Server\6.0\bin\mongod.cfg
8. I entered
security:
authorization: "enabled"
Under #security: section
mongoose.connect("mongodb://127.0.0.1:27017/posts")
and
mongoose.connect("mongodb://Admin:myNewPassword@localhost:27017/posts")
Both were connected successfully and in either cases data were stored in Databse!
*to be clearer My expected behavior was that the connection would have been failed in the first case! And data not stored in the database *
Thanks!
Found where the problem is! I had not restarted the MongoDB Server to have authorizations take effects! So I restarted MongoDB server in windows Services!