[英]Multi Upsert ArangoDB
我的收藏:
{"date": "5-1-2020", "country": "US", score: 0}
{"date": "5-1-2020", "country": "CA", score: 10}
{"date": "5-2-2020", "country": "US", score: 7}
{"date": "5-2-2020", "country": "CA", score: 11}
這是場景:我需要將 2020 年 5 月 1 日美國比賽的比分更新為 17。
偽代碼:
Search for date: "5-1-2020" and country "US".
If found UPDATE score to 17.
If not found insert record of {"date": "5-1-2020", "country": "US", score: 17}
我的工作解決方案:
FOR doc in collection
UPSERT { "date": "5-1-2020", "country": "US" }
INSERT doc
UPDATE { "score": 17 } in collection
如果我的收藏是:
{"date": "5-1-2020", "country": "CA", score: 10}
{"date": "5-2-2020", "country": "US", score: 7}
{"date": "5-2-2020", "country": "CA", score: 11}
解決方案/upsert 不起作用。
我想你的意思是這樣的:
UPSERT { "date": "5-1-2020", "country": "US" }
INSERT { "date": "5-1-2020", "country": "US", "score": 17 }
UPDATE { "score": 17 } IN collection
根據日期和國家/地區查找文檔並更新其分數,或插入帶有日期、國家和分數的新文檔。 請注意,沒有外部 FOR 循環,它會不必要地遍歷集合,並可能導致執行相同的更新數百次。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.