Fortgeschritten7 minAktualisiert: 2026-09-13

MongoDB 7: Authentication, Connection Strings, and mongodump Backups

Enable authentication on your MongoDB service, create an application user, build the right connection string, and set up regular backups.

Geprüft mit

MongoDB
7.0
Shell
mongosh 2.x
Zuletzt geprüft
2026-09-13
Auf dieser Seite
Alle Anleitungen
Lesefortschritt

MongoDB's most dangerous default is that authentication can be off. An internet-facing MongoDB with no password is found by scanning bots within minutes; this has been one of the most common data-breach scenarios for years. So the first thing to do is create an admin user and require authentication.

Turning on authentication#

mongosh
// admin veritabanina gec
use admin

// Yonetici kullanicisi
db.createUser({
  user: "yonetici",
  pwd: passwordPrompt(),
  roles: [{ role: "root", db: "admin" }]
})

// Uygulama icin ayri kullanici: yalnizca kendi veritabaninda yetkili
use uygulama_db
db.createUser({
  user: "uygulama",
  pwd: passwordPrompt(),
  roles: [{ role: "readWrite", db: "uygulama_db" }]
})

Building the right connection string#

Bağlantı dizesi
# authSource, kullanicinin TANIMLANDIGI veritabanidir;
# baglanacaginiz veritabani ile ayni olmak zorunda degil.
mongodb://uygulama:[email protected]:27017/uygulama_db?authSource=uygulama_db

# Yonetici kullanicisiyla baglanirken:
mongodb://yonetici:[email protected]:27017/?authSource=admin

Backing up with mongodump#

Yerel terminal
mongodump \
  --uri="mongodb://uygulama:[email protected]:27017/uygulama_db?authSource=uygulama_db" \
  --gzip --archive=yedek_$(date +%F).gz

Fehlerbehebung

Symptom

Authentication failed

Ursache

authSource is missing, or the user was created in a different database.

Lösung

Append ?authSource=<db where the user was created> to the connection string.

Symptom

Server starts but I cannot connect remotely

Ursache

bindIp is set to 127.0.0.1 only.

Lösung

Set bindIp to 0.0.0.0 in the service configuration and make sure authentication is enabled.

War diese Anleitung hilfreich?

Feedback geht direkt an das Team, das diese Anleitung pflegt.

Verwandte Anleitungen