一、ArangoDB基本单元
- 1.Collections
Collections相当于传统数据库的表,Collections有两种类型(不要和数据document混淆)
(1)document collection图的节点
(2)edge collection图的边
和document类型相比,多出_from和_to属性,表示两个document之间的联系,换句话说就是:
document collection的两个节点documents,通过edge collection边document来相连。
- 2.document文档
document 相当于传统数据库每一行数据,JSON格式,并自带3个属性,_key,_id,_rev
{
"_id":"users/559",
"_rev":"_Y4g7X_e--_",
"_key":"559"
}
二、AQL语句的使用
1.查询document
- 通过_key获取
RETURN DOCUMENT ("users","559")
- 通过_id获取
RETURN DOCUMENT ("users/559")
- 获取所有表中所有数据
FOR user IN users
RETURN user
- 条件查询
FOR c IN users
FILTER c.name=="Annie"
RETURN c
FOR c IN users
FILTER c.name=="Annie"
RETURN c.age
FOR c IN users
FILTER c.age<22 AND c.age!=null
RETURN {name:c.name,age:c.age}
- 限制查询的条数
FOR c IN users
limit 2
return c.name
- 排序(升序和降序)
for c in users
sort c.age,c.name
limit 10
return {name:c.name,age:c.age}
for c in users
sort c.age DESC,c.name
limit 10
return {name:c.name,age:c.age}
2.插入ducument
- 单条document数据插入
INSERT {"name":"linda","sex":"女"} INTO users
return NEW
- 多条document数据插入
LET data = [
{ "name": "Robert", "sex": "男", "age": 19},
{ "name": "Jaime", "sex": "女", "age": 20},
{ "name": "Catelyn", "sex": "女", "age": 23},
{ "name": "Cersei", "sex": "男", "age": 18},
{ "name": "Daenerys", "sex": "男", "age": 18}
]
FOR d IN data
INSERT d INTO users
3.更新和替换document
- 更新,根据_key
UPDATE "7292" WITH {
age:17
} IN users
- 替换
REPLACE "7292" WITH {
name:"Ned",
age:"19",
sex:"女"
}IN users
return NEW
- 新增属性
FOR user IN users
UPDATE user WITH {season:1} in users
4.删除document
- 单条删除
REMOVE "7292" IN users
- 批量删除
FOR c IN users
REMOVE c IN users
补充
- 返回2010至2019之间的年份
FOR year IN 2010..2019
RETURN year
本文介绍了ArangoDB的基本单元,包括Collections和Document,详细讲解了AQL语句的使用,涵盖查询、插入、更新、替换和删除操作。并提供了具体示例,如按_key和_id查询,条件限制,排序,单条和批量操作,以及如何更新和删除document。
---AQL语句使用&spm=1001.2101.3001.5002&articleId=94378346&d=1&t=3&u=45075166e66447e6906b3f0dd4692d3f)
1052

被折叠的 条评论
为什么被折叠?



