在ArangoDB中插入或更新文档失败,并违反了约束

时间:2018-12-08 21:31:50

标签: arangodb

我想在ArangoDB中获得Upsert,但是我无法通过create-document文档中提供的示例来使用它。我的请求失败,并显示一条unique constraint violated错误消息。

我将在集合中插入具有特定_key的文档,并且如文档中所述将overwrite选项设置为true,但仍然收到错误消息。这是在我的环境中所描述的curl调用的结果。

呼叫1:

curl -X POST --header 'accept: application/json'\
             --data-binary @- --dump - \
             http://localhost:8529/_api/document/products\?overwrite\=true \
<<EOF
{ "Hello": "Universe", "_key" : "lock" }
EOF

响应#1:

HTTP/1.1 202 Accepted
X-Content-Type-Options: nosniff
Location: /_db/_system/_api/document/products/lock
Etag: "_X28xHz---_"
Server: ArangoDB
Connection: Keep-Alive
Content-Type: application/json; charset=utf-8
Content-Length: 58  

{"_id":"products/lock","_key":"lock","_rev":"_X28xHz---_"}

呼叫2: (与第一个相同)

curl -X POST --header 'accept: application/json'\
             --data-binary @- --dump - \
             http://localhost:8529/_api/document/products\?overwrite\=true \
<<EOF
{ "Hello": "Universe", "_key" : "lock" }
EOF

响应#2:

HTTP/1.1 409 Conflict
X-Content-Type-Options: nosniff
Server: ArangoDB
Connection: Keep-Alive
Content-Type: application/json; charset=utf-8
Content-Length: 153

{"error":true,"errorMessage":"unique constraint violated - in index 0 of type primary over [\"_key\"]; conflicting key: lock","code":409,"errorNum":1210}

我仔细阅读了文档,启用并查看了服务器日志,但无法弄清楚。任何帮助将不胜感激。

编辑1:

以防万一,如果有什么帮助,我可以使用以下docker-compose在Docker本地运行ArangoDB服务器

version: '3'
services:
  db:
    image: arangodb
    ports:
    - "8529:8529"
    environment:
      ARANGO_NO_AUTH: 1
    volumes:
      - ./arangodb3:/var/lib/arangodb3
    command: "--log.level startup=trace --log.level requests=trace --log.level info"

这是服务器上的日志:

db_1  | 2018-12-09T08:56:16Z [1] DEBUG {requests} "http-request-begin","0x7f51ac946010","172.20.0.1","POST","HTTP/1.1","/_api/document/products?overwrite=true"
db_1  | 2018-12-09T08:56:16Z [1] TRACE {requests} "http-request-body","0x7f51ac946010","{ \"Hello\": \"Universe\", \"_key\" : \"lock\" }\n"
db_1  | 2018-12-09T08:56:16Z [1] TRACE {requests} "http-request-response","0x7f51ac946010","/_api/document/products?overwrite=true","HTTP\/1.1 409 Conflict\r\nX-Content-Type-Options: nosniff\r\nServer: ArangoDB\r\nConnection: Keep-Alive\r\nContent-Type: application\/json; charset=utf-8\r\nContent-Length: 153\r\n\r\n{\"error\":true,\"errorMessage\":\"unique constraint violated - in index 0 of type primary over [\\\"_key\\\"]; conflicting key: lock\",\"code\":409,\"errorNum\":1210}"
db_1  | 2018-12-09T08:56:16Z [1] TRACE {requests} "http-request-statistics","0x7f51ac946010","172.20.0.1","POST","HTTP/1.1",409,41,153,"/_api/document/products?overwrite=true",read,0.000124931,queue,0.000000000,queue-size,0,request,0.000008106,total,0.017638445,error,false
db_1  | 2018-12-09T08:56:16Z [1] INFO {requests} "http-request-end","0x7f51ac946010","172.20.0.1","POST","HTTP/1.1",409,41,153,"/_api/document/products?overwrite=true",0.017630

1 个答案:

答案 0 :(得分:2)

我在ArangoDB社区的闲暇通道上发布了这个问题,那里的好人指出,仅在3.4中才引入了通过overwrite参数进行替换插入。根据我的docker compose,我的图像指向了{em> arangodb 的Official Docker Repository的最新图像,即3.3.20

有人向我解释说,这个“官方”存储库(arangodb)不一定托管ArangoDB的最新稳定版本,它可能需要几天的时间才能提供,我应该指向{{1} }。

我修改了arangodb/arangodb文件以使用正确的图像,现在它可以正常工作了。

docker-compose.yml:

docker-compose.yml

再次感谢您在Slack上的ArangoDB社区,尤其是@mpoeter!