use admin
db.createUser(
{ user: "username",
pwd: "password",
roles:[{role: "root" , db:"admin"}]})db.updateUser( "username",
{
roles : [
{ role : "read", db : "database" }
]
}
)rs.printSecondaryReplicationInfo() #показать статус репликации
show users # посмотреть всех пользователей, запускается на мастер ноде
db.changeUserPassword("accountUser", "SOh3TbYhx8ypJPxmt1oOfL") #смена пароляdb.currentOp(true).inprog.forEach(function(d){if (d.client)printjson(d.client)})db.currentOp(true).inprog.reduce((accumulator, connection) => { ipaddress = connection.client ? connection.client.split(":")[0] : "unknown"; accumulator[ipaddress] = (accumulator[ipaddress] || 0) + 1; accumulator["TOTAL_CONNECTION_COUNT"]++; return accumulator; }, { TOTAL_CONNECTION_COUNT: 0 })Backup/Restore и архив
Backup RepliceSet в secondary ноды в архив с Oplog с записью лога
mongodump --uri="mongodb://username:password@host1:27017,host2:27017,host3:27017/?replicaSet=rs_name&readPreference=secondary" --oplog --archive="file_patch" 1> log patch 2>&1
mongorestore --username username mongodb://host_target:27017 --archive="archive_patch" --nsInclude="Database.*"
db.getProfilingStatus(); # посмотреть настройки профилирования db.setProfilingLevel(0, 2500) # изменить настройки на более 2500 мс
db.adminCommand( { logRotate : 1 } ) # пересоздает файл журналаdb.shutdownServer()
Побита база, служба останавливается и падает. Добавьте значение в свойства службы, чтобы она не падала по timeout, есть вероятно, что через несколько часов база восстановится
TimeoutSec=0
cfg = rs.conf() # смотрим текущие значения cfg.members[0].priority = 2 # повышаем приоритет ноды 0 rs.reconfig(cfg) # применяем изменения
db.currentOp(true).inprog.reduce((accumulator, connection) => { ipaddress = connection.client ? connection.client.split(":")[0] : "unknown"; accumulator[ipaddress] = (accumulator[ipaddress] || 0) + 1; accumulator["TOTAL_CONNECTION_COUNT"]++; return accumulator; }, { TOTAL_CONNECTION_COUNT: 0 })use sample_mflix
db.humans_bureau_creditreports.deleteMany({})
https://www.mongodb.com/docs/mongodb-shell/crud/delete/