在以下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
}
]
}
答案 0 :(得分:12)
要获取任何产品的销售价值至少超过12,500的所有文档,您可以在ReQL中使用以下过滤器:
r.table('t')
.filter(r.row('products').contains(function(product) {
return product('sales').gt(12500);
}))
这可以利用您可以将函数传递给contains
的事实。如果array.contains(fun)
为true
中的至少一个元素返回fun
,则true
会完全返回array
。
您可以在http://rethinkdb.com/api/javascript/contains/