【发布时间】:2018-04-24 16:23:41
【问题描述】:
我在尝试从我的表中删除嵌套对象时遇到了很大的困难,而在此过程中不会意外删除我的所有数据(现在发生了 3 次,感谢上帝我复制了)。
我的对象:
{
"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()
}
非常感谢任何帮助,如果问题有问题,请告诉我。对此仍然相当新,因此感谢您的反馈。
【问题讨论】:
标签: javascript json node.js rethinkdb rethinkdb-javascript