文档数据库服务 DDS-更新用户:示例

时间:2024-09-11 16:05:18

示例

  • 更新用户信息

    products数据库中的用户appClient01,其信息如下:

    {
    	"_id" : "products.appClient01",
    	"token" : NumberLong("8424642624807814713"),
    	"user" : "appClient01",
    	"db" : "products",
    	"customData" : {
    		"empID" : "12345",
    		"badge" : "9156"
    	},
    	"roles" : [
    		{
    			"role" : "readWrite",
    			"db" : "products"
    		},
    		{
    			"role" : "read",
    			"db" : "inventory"
    		}
    	],
    	"mechanisms" : [
    		"SC RAM -SHA-1",
    		"SCRAM-SHA-256"
    	]
    }

    下面操作会替换用户的自定义数据和角色数据:

    use products
    db.updateUser( "appClient01",
    {
       customData : { employeeId : "0x3039" },
       roles : [
          { role : "read", db : "assets"  }
       ]
    } )

    products数据库中的用户appClient01,经过更新后信息如下:

    {
    	"_id" : "products.appClient01",
    	"token" : NumberLong("8424642624807814713"),
    	"user" : "appClient01",
    	"db" : "products",
    	"customData" : {
    		"employeeId" : "0x3039"
    	},
    	"roles" : [
    		{
    			"role" : "read",
    			"db" : "assets"
    		}
    	],
    	"mechanisms" : [
    		"SCRAM-SHA-1",
    		"SCRAM-SHA-256"
    	]
    }
  • 更新用户以仅使用SCRAM-SHA-256凭证

    reporting数据库中的用户reportUser256,其信息如下:

    {
    	"_id" : "reporting.reportUser256",
    	"token" : NumberLong("2827251846225877395"),
    	"user" : "reportUser256",
    	"db" : "reporting",
    	"roles" : [ ],
    	"mechanisms" : [
    		"SCRAM-SHA-1",
    		"SCRAM-SHA-256"
    	]
    }

    以下操作会将当前同时拥有 SCRAM-SHA-256 和 SCRAM-SHA-1 全权证书的用户更新为只拥有 SCRAM-SHA-256 全权证书的用户。

    • 如果密码未与mechanisms一起指定,则只能将mechanisms更新为用户当前SCRAM机制的子集。
    • 如果密码与mechanisms一起指定,则可以指定任何受支持的SCRAM机制。
    • 对于SCRAM-SHA-256,passwordDigestor必须是默认值 "server"。
    db.updateUser(
       "reportUser256",
       {
         mechanisms: [ "SCRAM-SHA-256" ]
       }
    )

    reporting数据库中的用户reportUser256,经过更新后信息如下:

    {
    	"_id" : "reporting.reportUser256",
    	"token" : NumberLong("2827251846225877395"),
    	"user" : "reportUser256",
    	"db" : "reporting",
    	"roles" : [ ],
    	"mechanisms" : [
    		"SCRAM-SHA-256"
    	]
    }
support.huaweicloud.com/dds_faq/dds_devg_0098.html