0
在MySql中,我們創建了兩個模型用戶和友誼的簡單用戶友情數據庫。是ArangoDB邊緣文件放置附加鍵值的正確位置嗎?
模型友誼包含鍵:(REF鍵)
- ID
- 從(REF鍵)
- 到
- 創建
- 改性
- 批准(0,1 )
- block(0,1)
在ArangoDB中製作相同的正確方法是什麼? 有沒有添加關鍵值的「友誼」邊緣文檔? 是否可以執行更新邊緣文檔? 另外,執行請求後可能會顯示這些值嗎?
在MySql中,我們創建了兩個模型用戶和友誼的簡單用戶友情數據庫。是ArangoDB邊緣文件放置附加鍵值的正確位置嗎?
模型友誼包含鍵:(REF鍵)
在ArangoDB中製作相同的正確方法是什麼? 有沒有添加關鍵值的「友誼」邊緣文檔? 是否可以執行更新邊緣文檔? 另外,執行請求後可能會顯示這些值嗎?
給我一個例子。
首先創建一個「用戶」集合和一個「友誼」集合。
arangosh [_system]> db._create("users");
[ArangoCollection 33746098, "users" (type document, status loaded)]
arangosh [_system]> db._createEdgeCollection("friendship");
[ArangoCollection 33877170, "friendship" (type edge, status loaded)]
創建兩個用戶
arangosh [_system]> db.users.save({_key: "you"});
{
"_id" : "users/you",
"_rev" : "34598066",
"_key" : "you"
}
arangosh [_system]> db.users.save({_key: "me"});
{
"_id" : "users/me",
"_rev" : "34794674",
"_key" : "me"
}
以及它們之間
arangosh [_system]> db.friendship.save("users/me", "users/you", {});
{
"_id" : "friendship/35515570",
"_rev" : "35515570",
"_key" : "35515570"
}
檢查用戶
arangosh [_system]> db._query("FOR u IN users RETURN u").toArray()
[
{
"_id" : "users/me",
"_rev" : "34794674",
"_key" : "me"
},
{
"_id" : "users/you",
"_rev" : "34598066",
"_key" : "you"
}
]
及其鄰國
的關係arangosh [_system]> db._query("FOR u IN users RETURN { user: u, friends: NEIGHBORS(users, friendship, u, 'outbound') }").toArray()
[
{
"user" : {
"_id" : "users/me",
"_key" : "me",
"_rev" : "34794674"
},
"friends" : [
"users/you"
]
},
{
"user" : {
"_id" : "users/you",
"_key" : "you",
"_rev" : "34598066"
},
"friends" : [ ]
}
]
附加 「塊」
arangosh [_system]> db._query("FOR f IN friendship FILTER f._from == 'users/me' and f._to == 'users/you' UPDATE f WITH { block: true } IN friendship RETURN { before: OLD, after: NEW }").toArray()
[
{
"before" : {
"_id" : "friendship/35515570",
"_rev" : "35515570",
"_key" : "35515570",
"_from" : "users/me",
"_to" : "users/you"
},
"after" : {
"block" : true,
"_id" : "friendship/35515570",
"_rev" : "63892658",
"_key" : "35515570",
"_from" : "users/me",
"_to" : "users/you"
}
}
]
返回將返回整個文檔。您也可以只返回塊屬性
arangosh [_system]> db._query("FOR f IN friendship FILTER f._from == 'users/me' and f._to == 'users/you' UPDATE f WITH { block: false } IN friendship RETURN { before: OLD.block, after: NEW.block }").toArray()
[
{
"before" : true,
"after" : false
}
]
感謝您的好解釋。 – Salines