arango增删改查

arango实践

  • 插入数据
INSERT document INTO collection options
  • 修改数据
UPDATE document IN collection options // 修改文档里面所有数据
UPDATE keyExpression WITH document IN collection options //根据key值修改文档
  • 插入数据
 //插入数据到user集合
 INSERT { name: "Katie Foster", age: 27 } INTO users 
 FOR user IN users  RETURN user 
  • 查询数据
FOR user IN users  SORT user.age DESC  RETURN user  //按年龄倒叙排序查询user集合数据数据

FOR user IN users  FILTER user.age > 17  SORT user.age  RETURN user //查询年龄>17按年龄顺序排序的user集合数据

UPDATE "16097" WITH { age: 40 } IN users RETURN NEW  //更新users集合中_key为“16097”的用户的年龄为40

FOR user IN users  RETURN { userName: user.name, age: user.age } //查询user集合的姓名和年龄
FOR user IN users  RETURN CONCAT(user.name, "'s age is ", user.age) //把user集合的姓名和年龄组合在一起
REMOVE "9883" IN users //删除users集合中_key为“9883”的文档
  
  • 复杂查询
 /*
 在germanCity集合里按是否是首都(isCapital)分组统计数量
 */
 FOR city IN germanCity
   COLLECT isCapital = city.isCapital 
     WITH COUNT INTO number
   RETURN { 
     isCapital: isCapital, 
     number: number 
   }
   
   
 /*
 统计用户最大年龄和最小年龄
 */
 FOR user IN users
   FILTER user.age != null
   COLLECT AGGREGATE
     minAge = MIN(user.age),
     maxAge = MAX(user.age)
   RETURN { minAge, maxAge }
   
   /*
   在relation集合里面按关系类型(type)进行分组统计数量
   */
     FOR rl IN relation
   FILTER rl.type == 'friend'
   COLLECT type = rl.type 
     WITH COUNT INTO number
   RETURN { 
     type: type, 
     number: number 
   }
 
   
  /*
  最大年龄,最小年龄
 */ 
   FOR user IN users
   FILTER user.active == 1
   COLLECT AGGREGATE
     minAge = MIN(user.age),
     maxAge = MAX(user.age)
   RETURN { minAge, maxAge }
   
 
  • 多表查询
  /*
    集合users和friends通过user和_key字段连接查询
  */
    FOR user IN users 
    FOR friend IN friends
      FILTER friend.user == user._key
      RETURN MERGE(user, friend)
  ```

- 图查询

```sql
//最短路径
FOR female, relation 
IN ANY SHORTEST_PATH
'male/bob' TO 'female/diana' 
GRAPH 'social'
return [female._key,male._key,relation.type]

你可能感兴趣的:(arango增删改查)