嗨,伙计们,
我在mongo db收藏了:
{
"_id" : "aghpbF6xxxCyMGg9J",
"description" : "",
"name" : "test",
"roles" : [
"ab.read",
"test.view"
],
"type" : "group"
}我有testRoles对象:
[ { name: 'testRoles',
permissions: [ 'ab.write', 'test.check' ] } ],基本上,我需要做的是,用来自testRoles对象的字段权限替换db中的字段角色,谁能帮我管理一下吗?
发布于 2021-12-27 22:14:50
您可以简单地$set所需的字段并替换整个数组,如下所示:
db.collection.updateOne(
{} // empty match since idk what your match parameter is ;)
,{
$set: {
"roles": ['a', 'b'] // this is your value from the object
}
})https://stackoverflow.com/questions/70500883
复制相似问题