Reputation: 37
I'm running hops against a dataset in sesam and my output is as the example below, my problem is that need a join where i only end up with the property with the highest priority.
[{
"id": "AAA",
"priority": 10
}, {
"id": "AAB",
"priority": 7
}]
Upvotes: 1
Views: 60
Reputation: 61
You can also solve this with the "max" function:
{
"_id": "sort-by-prop",
"type": "pipe",
"source": {
"type": "embedded",
"entities": [{
"_id": "foo",
"bar": [{
"id": "AAA",
"priority": 10
}, {
"id": "AAB",
"priority": 5
}]
}]
},
"transform": {
"type": "dtl",
"rules": {
"default": [
["copy", "_id"],
["add", "foo",
["path", "id",
["max", "_.priority", "_S.bar"]
]
]
]
}
}
}
The result will be:
[
{
"_id": "foo",
"foo": "AAA"
}
]
Upvotes: 2
Reputation: 375
You can solve this using "sorted", "reverse", "first" and "path":
{
"_id": "sort-by-prop",
"type": "pipe",
"source": {
"type": "embedded",
"entities": [{
"_id": "foo",
"bar": [{
"id": "AAA",
"priority": 10
}, {
"id": "AAB",
"priority": 5
}]
}]
},
"transform": {
"type": "dtl",
"rules": {
"default": [
["copy", "_id"],
["add", "foo",
["path", "id",
["first",
["reversed",
["sorted", "_.priority", "_S.bar"]
]
]
]
]
]
}
}
}
The result will be:
[
{
"_id": "foo",
"foo": "AAA"
}
]
Upvotes: 1