大家好,
我在 mongo db 集合中有:
{
"_id" : "aghpbF6xxxCyMGg9J",
"description" : "",
"name" : "test",
"roles" : [
"ab.read",
"test.view"
],
"type" : "group"
}
我有 testRoles 物件:
[ { name: 'testRoles',
permissions: [ 'ab.write', 'test.check' ] } ],
基本上我需要做的是,用 testRoles 物件的欄位權限替換資料庫中的欄位角色,請任何人都可以幫我管理它嗎?
uj5u.com熱心網友回復:
您可以簡單地 $set 所需的欄位并像這樣替換整個陣列:
db.collection.updateOne(
{} // empty match since idk what your match parameter is ;)
,{
$set: {
"roles": ['a', 'b'] // this is your value from the object
}
})
uj5u.com熱心網友回復:
testRoles 中的角色:db.collection.update_many.update_one({'name': role['name']},{$set : {'roles': role['permission']}})
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/395477.html
標籤:javascript 数据库 MongoDB 流星火
上一篇:如何從資料庫顯示img
