在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ 數(shù)據(jù)庫/ MongoDB更改用戶密碼和自定義數(shù)據(jù)
MongoDB教程
MongoDB覆蓋查詢
MongoDB數(shù)據(jù)建模
MongoDB聚合
MongoDB更改用戶密碼和自定義數(shù)據(jù)
MongoDB用戶
MongoDB分片
MongoDB創(chuàng)建集合
MongoDB文本搜索
MongoDB數(shù)據(jù)類型
MongoDB GridFS
MongoDB索引限制
MongoDB插入文檔
MongoDB刪除集合
MongoDB數(shù)據(jù)庫引用
MongoDB復(fù)制
MongoDB Map Reduce
Python連接MongoDB操作
MongoDB原子操作
MongoDB特點(diǎn)
MongoDB安全檢查表
MongoDB排序記錄
MongoDB自動遞增序列
MongoDB安裝配置(Windows)
MongoDB備份與恢復(fù)
MongoDB安裝配置(Ubuntu)
Ruby連接MongoDB操作
MongoDB部署
MongoDB索引
MongoDB分析查詢
MongoDB投影(選擇字段)
MongoDB刪除數(shù)據(jù)庫
MongoDB認(rèn)證
MongoDB限制記錄數(shù)
MongoDB添加用戶
MongoDB固定循環(huán)集合
MongoDB高級索引
MongoDB數(shù)據(jù)庫的優(yōu)點(diǎn)
MongoDB快速入門
MongoDB創(chuàng)建數(shù)據(jù)庫
MongoDB啟用身份驗(yàn)證
MongoDB歷史
MongoDB管理用戶和角色
MongoDB安裝配置(RedHat/CentOS)
MongoDB刪除文檔
Java連接MongoDB操作
MongoDB正則表達(dá)式
MongoDB查詢文檔
MongoDB關(guān)聯(lián)關(guān)系
PHP連接MongoDB操作
MongoDB更新文檔
MongoDB ObjectId

MongoDB更改用戶密碼和自定義數(shù)據(jù)

具有適當(dāng)權(quán)限的用戶可以更改自己的密碼和自定義數(shù)據(jù)。 自定義數(shù)據(jù)存儲可選的用戶信息。

注意事項(xiàng)

在此過程要生成一個強(qiáng)大的密碼,您可以使用openssl實(shí)用程序的rand命令。 例如,使用以下選項(xiàng)發(fā)出openssl rand,以創(chuàng)建48個偽隨機(jī)字節(jié)的base64編碼字符串:

openssl rand -base64 48

先決條件

要修改自己的密碼和自定義數(shù)據(jù),您必須具有在用戶數(shù)據(jù)庫上分別授予changeOwnPasswordchangeOwnCustomData操作的權(quán)限。

第一步:使用相應(yīng)的權(quán)限連接到MongoDB

使用“先決條件”部分指定的權(quán)限連接到 mongodmongos 。

以下過程使用在“啟用認(rèn)證”中創(chuàng)建的用戶:myUserAdmin。

$ mongo --port 27017 -u "myUserAdmin" -p "abc123" --authenticationDatabase "admin"

第二步:使用適當(dāng)?shù)臋?quán)限創(chuàng)建角色

在管理數(shù)據(jù)庫中,使用changeOwnPasswordchangeOwnCustomData創(chuàng)建一個新角色。

use admin
db.createRole(
   { role: "changeOwnPasswordCustomDataRole",
     privileges: [
        {
          resource: { db: "", collection: ""},
          actions: [ "changeOwnPassword", "changeOwnCustomData" ]
        }
     ],
     roles: []
   }
)

第三步:添加具有此角色的用戶

test數(shù)據(jù)庫中,使用創(chuàng)建的“changeOwnPasswordCustomDataRole”角色創(chuàng)建一個新用戶。 例如,以下操作將創(chuàng)建具有內(nèi)置角色readWrite和用戶創(chuàng)建的“changeOwnPasswordCustomDataRole”的用戶。

use test
db.createUser(
   {
     user:"user123",
     pwd:"12345678",
     roles:[ "readWrite", { role:"changeOwnPasswordCustomDataRole", db:"admin" } ]
   }
)

要向現(xiàn)有用戶授予新角色,請使用db.grantRolesToUser()。

執(zhí)行過程

第一步:使用相應(yīng)的權(quán)限連接到MongoDB

使用“先決條件”部分指定的權(quán)限連接到 mongodmongos 。

以下過程使用在“啟用認(rèn)證”中創(chuàng)建的用戶:myUserAdmin。

$ mongo --port 27017 -u "myUserAdmin" -p "abc123" --authenticationDatabase "admin"

要檢查您是否具有先決條件部分中指定的權(quán)限以及查看用戶信息,請使用帶有--showPrivileges選項(xiàng)的usersInfo命令。

第二步:更改您的密碼和自定義數(shù)據(jù)

使用db.updateUser()方法來更新密碼和自定義數(shù)據(jù)。

例如,以下操作將用戶的密碼更改為:KNlZmiaNUp0B,并將自定義數(shù)據(jù)更改為{title:“Senior Manager”}

use test
db.updateUser(
   "user123",
   {
      pwd: "KNlZmiaNUp0B",
      customData: { title: "Senior Manager" }
   }
)