MongoDB security has two distinct layers: authentication (who are you?) and authorization (what can you do?). Both are disabled by default in standalone development installations — production deployments must enable both.
--auth flag or security.authorization: enabled in mongod.conf.// Enable authentication in mongod.conf: security: authorization: enabled // Or via command line flag: mongod --auth --dbpath /data/db // First: create admin user before enabling auth // (Local Exception: when no users exist, localhost can connect without auth) use admin db.createUser({ user: "adminUser", pwd: "securePassword123!", roles: [{ role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase"] })