如何更新 rethinkDB 中的嵌套对象 [英] How to update a nested object in rethinkDB
本文介绍了如何更新 rethinkDB 中的嵌套对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在更新嵌套对象时遇到问题.像这样的示例数据
I am getting an issue while updating a nested object.sample data like this
{
"status":{
"draft":{
"status":"draft",
"rating":4
},
"review":{
"status":"review",
"rating":4
},
"publish":{
"status":"publish",
"rating":4
}
}
}
在上面的对象中,有时draft/review/publish是空对象,需要检查条件并更新rating对象.我试过这样但出错.
In the above object some times the draft/ review/ publish are empty objects and need to check the condition and update the rating in the object.I have tried like this but getting error.
查询:
r.db('sample_db').table('table').filter({id:'xxxxxxx'})
.update({"draft": r.row('status').map(function(data){
return r.branch(
data('draft').hasFields({'status':true}),
data.merge({ "rating": 100 }),
data
)})
})
错误:
{
"deleted": 0 ,
"errors": 1 ,
"first_error": "Cannot convert OBJECT to SEQUENCE" ,
"inserted": 0 ,
"replaced": 0 ,
"skipped": 0 ,
"unchanged": 0
}
谁能帮我解决这个查询.提前致谢.
can any one help me to solve this query. Thanks in advance.
推荐答案
我不确定您在这里到底想做什么.但是要根据是否包含状态字段来更新草稿元素内的评分,您需要执行以下操作:
I am not sure exactly what you are trying to do here. But to update the rating inside the draft element depending whether it contains a status field you do:
r.db('sample_db').table('table').get('idxxxxxxx')
.update(function(e){
return r.branch(e('status')('draft').hasFields('status'),
{'status':{'draft':{'rating':100}}}, e)
})
这篇关于如何更新 rethinkDB 中的嵌套对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文