KAd*_*ude 4 json filter nested-query rethinkdb reql
在以下JSON中,我想选择销售额> 12500的记录.如何在ReThinkDB和ReQL中执行此操作?
JSON是:
{
"address": {
"address_line1": "Address Line 1" ,
"address_line2": "Address Line 2" ,
"city": "Kochin" ,
"country": "India" ,
"state": "Kerala"
} ,
"id": "bbe6a9c4-ad9d-4a69-9743-d5aff115b280" ,
"name": "Dealer 1" ,
"products": [
{
"product_name": "Stabilizer" ,
"sales": 12000
} ,
{
"product_name": "Induction Cooker" ,
"sales": 14000
}
]
}, {
"address": {
"address_line1": "Address Line 1" ,
"address_line2": "Address Line 2" ,
"city": "Kochin" ,
"country": "India" ,
"state": "Kerala"
} ,
"id": "f033a4c2-959c-4e2f-a07d-d1a688100ed7" ,
"name": "Dealer 2" ,
"products": [
{
"product_name": "Stabilizer" ,
"sales": 13000
} ,
{
"product_name": "Induction Cooker" ,
"sales": 11000
}
]
Run Code Online (Sandbox Code Playgroud)
}
Dan*_*wes 13
要获取任何产品的至少一个销售价值超过12,500的所有文档,您可以在ReQL中使用以下过滤器:
r.table('t')
.filter(r.row('products').contains(function(product) {
return product('sales').gt(12500);
}))
Run Code Online (Sandbox Code Playgroud)
这利用了可以传递函数的事实contains.如果至少返回其中一个元素,则array.contains(fun)返回true完全fun返回.您可以在http://rethinkdb.com/api/javascript/contains/找到更多示例truearray
| 归档时间: |
|
| 查看次数: |
6080 次 |
| 最近记录: |