arangodb 实用笔记
auth:wangjing
date:2021-03-24
INSERT
insert document
insert {
"name":"张三",
"age":"27",
"birthday":"1994-10-01",
"alive":"ture",
} INTO new_doc
insert document batch
let data =[
{"name":"张三","age":"27","birthday":"1994-10-01","alive":"ture"},
{"name":"张三","age":"27","birthday":"1994-10-01","alive":"ture"},
{"name":"张三","age":"27","birthday":"1994-10-01","alive":"ture"},
{"name":"张三","age":"27","birthday":"1994-10-01","alive":"ture"},
{"name":"张三","age":"27","birthday":"1994-10-01","alive":"ture"}
]
for d in data
insert d into new_doc
Insert edge
INSERT {_from:"new_doc/50072560",_to:"new_doc/50072501"} into new_edge
return "ok"
Insert with edge
INSERT {_from:"new_doc/50072560",_to:"new_doc/50072501",edge:"朋友"} into new_edge
return "ok"
REMOVE
根据_key值删除
REMOVE "19579" IN info2021
我们还可以循环删除文档
对于INSERT,UPDATE和REPLACE来说也是如此
FOR info IN info2021 FILTER info.age >= 30 REMOVE info IN info2021
UPDATE
将_key为19579的记录的age字段从25更新到60
UPDATE "19579" WITH { age: 60 } IN info2021
查询
return documents
for d in new_doc return d
return document record A
//单条记录
return document("new_doc/50072560")
return document record B
RETURN DOCUMENT( ["info2021/19579", "info2021/19768", "info2021/20234"] )
return document record C
//单条记录
for d in new_doc
return {"主键":d._id,"姓名":d.birthday}
return document record D
for c in new_doc
FILTER c.name == '张三'
return c
return edges
for d in new_edge return d
return edges 4 bob
for e in knows
filter e._from == "persons/bob"
OR e._to == "persons/bob"
return e
return edges 4 edge
for d in new_edge
filter d.edge == "朋友"
return d
查询对象与对象关系
for c in new_doc
FILTER c.name == '张三'
//一级关系
for v in 1..1
OUTBOUND c new_edge
return c
查询直接关系有问题
for r in new_edge
FILTER r._from==s._id
for e in new_doc
FILTER r._to == e._id
return {s:s,r:r,e:e}
高级分析
for s in persons
for r in knows
FILTER r._from==s._id
for e in persons
FILTER r._to == e._id
//return {s:s,r:r,e:e}
return {
"_id": r._id,
"_from": s._id,
"_to": e._id,
"s_s":s,
"e_e":e
}
some code
for c in new_doc FILTER c.name == '张三'
//直接关系
for v in 1..1 OUTBOUND c new_edge
return c
//查对象与对象关系
for s in new_doc FILTER s.name == '张三'
//直接关系
for r in new_edge
FILTER r._from==s._id
for e in new_doc
FILTER r._to == e._id
return {s:s,r:r,e:e}
路径匹配
鸟A → 鸟B → 鸟C
鸟A与鸟C为2级关系