Reputation: 11
How to query and return all channels with matching channelId, from a document:
As an example, my rethink table contains the following document:
{
"agreement_id": "5",
"channels": [
{
"channelId": "8deb-6b37-4678115-917d-ad365ae57e19",
"lab_cost": 333,
"learner_cost": 30,
"net_revenue": 20.87,
"orgId": "gmudam",
"publisher": "oci-jumpstart",
"publisher_revenue": 4.97,
"ql_revenue": 16.9,
"realm_cost": 1.13
},
{
"channelId": "8deb-6b37-4678115-917d-ad365ae57e19",
"lab_cost": 444,
"learner_cost": 30,
"net_revenue": 20.87,
"orgId": "gmudam",
"publisher": "oci-jumpstart",
"publisher_revenue": 4.97,
"ql_revenue": 16.9,
"realm_cost": 1.13
}
]
}
Upvotes: 0
Views: 774
Reputation: 3040
To extract all channels by channelId from a document, you can do the following:
r.db("DB").table("TABLE").get("agreement_id")("channels")
.filter(function(channel){
return channel("channelId").eq("8deb-6b37-4678115-917d-ad365ae57e19")})
This will give you all channels with the id "8deb-6b37-4678115-917d-ad365ae57e19". E.g:
[
{
"channelId": "8deb-6b37-4678115-917d-ad365ae57e19",
"lab_cost": 333,
"learner_cost": 30,
"net_revenue": 20.87,
"orgId": "gmudam",
"publisher": "oci-jumpstart",
"publisher_revenue": 4.97,
"ql_revenue": 16.9,
"realm_cost": 1.13
},
{
"channelId": "8deb-6b37-4678115-917d-ad365ae57e19",
"lab_cost": 444,
"learner_cost": 30,
"net_revenue": 20.87,
"orgId": "gmudam",
"publisher": "oci-jumpstart",
"publisher_revenue": 4.97,
"ql_revenue": 16.9,
"realm_cost": 1.13
}
]
Upvotes: 0