【问题标题】:ArangoDB create Vertex REST API without knowing the vertex id'sArangoDB 在不知道顶点 id 的情况下创建顶点 REST API
【发布时间】:2015-06-24 20:12:46
【问题描述】:

有没有办法在不知道顶点 ID 的情况下使用 ArangoDB 使用 REST API 创建边缘?通过查询查找顶点并链接它们?

与 OrientDB 类似:create edge Uses from (select from Module where name = 'm2') to (select from Project where name = 'p1')

我不想通过 REST 查询创建边缘之前和之后的两个顶点。我也不想用 Foxx。

也许使用 AQL?

谢谢。

【问题讨论】:

    标签: rest arangodb


    【解决方案1】:

    是的,只需一个 AQL 查询即可:

    LET from = (FOR doc IN Module FILTER doc.name == 'm2' RETURN doc._id)
    LET to   = (FOR doc IN Project FILTER doc.name == 'p1' RETURN doc._id)
    INSERT { 
      _from: from[0], 
      _to: to[0], 
      /* insert other edge attributes here as needed */ 
      someOtherAttribute: "someValue" 
    }
    INTO nameOfEdgeCollection
    

    【讨论】:

    • 太棒了!但它不适用于 REST API。相同的 AQL 波纹管在 AQL 编辑器中工作正常。 curl -X POST --dump - localhost:8529/_db/database/_api/cursor --data '{query:LET from = (FOR p IN products FILTER p.name == "p1" RETURN p._id) LET to=(FOR p IN products FILTER p .name == "p2" RETURN p._id) INSERT { _from: from[0], _to: to[0], type: "RELATED" } INTO productsedge}' HTTP/1.1 400 Bad Request Server: ArangoDB Connection: Keep -活动内容类型:应用程序/json; charset=utf-8 Content-Length: 82 {"error":true,"errorMessage":"expecting attribute name","code":400,"errorNum":600}
    • 您需要确保将正确编码的 JSON 发送到服务器。上述数据不是有效的 JSON,因为属性名称和值都没有用双引号括起来。应该是curl ... --data '{"query":"LET from = (FOR p IN products FILTER p.name == \"p1\" RETURN p._id) LET to=(FOR p IN products FILTER p.name == \"p2\" RETURN p._id) INSERT { _from: from[0], _to: to[0], type: \"RELATED\" } INTO productsedge"}'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多