我在尝试从表中删除嵌套对象而不意外删除过程中的所有数据时遇到了相当大的困难(现在发生了三次,感谢上帝我制作了副本)。
我的对象:
{
"value1": thing,
"value2": thing,
"value3": thing,
"roles": {
"1": {
"name": "Dave",
"id": "1"
},
"2": {
"name": "Jeff",
"id": "2"
},
"3": {
"name": "Rick",
"id": "3"
},
"4": {
"name": "Red",
"id": "4"
}
}
}`
我已经尝试了一些重新思考查询,但到目前为止没有一个有效。应该注意的是,1、2、3 和 4 是可以具有任意数量数字的变量,因此我的查询必须反映这一点。
一些尝试的查询:
function removeRole(id, roleName) {
let role = `${roleName}`
return this.r.table('guilds').get(id).replace(function(s){
return s.without({roles : {[role] : { "name": role }}})
})
}
function removeRole(id, roleName) {
return this.r.table('guilds').getAll(id).filter(this.r.replace(this.r.row.without(roleName))).run()
}
function removeRole(id, roleName) {
return this.r.table('guilds').get(id)('roles')(roleName).delete()
}
非常感谢任何帮助,如果问题有问题,请告诉我。对此仍然相当陌生,因此感谢反馈。