我正在使用类似于 ArangoDB 官方“友谊”示例的数据集,除了我在边缘集合上添加了一个“权重”概念。像这样:
人们
[
{ "_id": "people/100", "_key": "100", "name": "John" },
{ "_id": "people/101", "_key": "101", "name": "Fred" },
{ "_id": "people/102", "_key": "102", "name": "Jacob" },
{ "_id": "people/103", "_key": "103", "name": "Ethan" }
]
友谊
[
{ "_from": "people/100", "_to": "people/101", "weight": 27 },
{ "_from": "people/103", "_to": "people/102", "weight": 31 },
{ "_from": "people/102", "_to": "people/100", "weight": 12 },
{ "_from": "people/101", "_to": "people/103", "weight": 56 }
]
我想编写一个函数,当有人与其他人交互时,UPSERTs 两者之间的友谊(如果之前存在,则将权重增加 1,如果它是新的,则将权重初始化为 1)。
问题是,在执行该函数时,我现在知道友谊被初始化的方向,因此我不能真正使用 upsert。所以这里有两个问题:
- 有没有办法用“双向”过滤器在边缘上做一个 upsert ?
像这样,但双向
UPSERT {
// HERE, I BASICALLY WAN'T TO IGNORE THE SIDE
_from: ${people1}, _to: ${people2}
}
INSERT {
_from: ${people1}, _to: ${people2}, weight: 1
}
UPDATE {
weight: OLD.weight + 1
}
IN ${friendshipCollection}
RETURN NEW
- 而不是试图“选择友谊,无论方向”;我是否应该实际上在两个方向上复制友谊(并不断维护/更新它)?