簡體   English   中英

在ArangoDB中插入或更新文檔失敗,並違反了約束

[英]Insert or update a document in ArangoDB fails with constraint violated

我想在ArangoDB中實現Upsert,但是我無法通過create-document文檔中提供的示例來使用它。 我的請求失敗,並顯示unique constraint violated錯誤消息。

我正在集合中插入具有特定_key的文檔,並且overwrite文檔中說明的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本地運行ArangoDB服務器,並使用以下docker-compose

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

我在ArangoDB社區的閑散通道上發布了這個問題,那里的好人向我指出,僅在3.4以來才引入了通過overwrite參數進行的替換插入。 基於我的docker compose,我的圖像指向arangodb官方Docker倉庫的最新圖像,即3.3.20

有人向我解釋說,這個“官方”存儲庫( arangodb )不一定托管arangodb的最新穩定版本,它可能需要幾天的時間才能提供,我應該指向arangodb/arangodb

我修改了docker-compose.yml文件以使用正確的圖像,現在它可以正常工作。

泊塢窗,compose.yml:

version: '3'
services:
  db:
    image: arangodb/arangodb:3.4.0
    ports:
    - "8529:8529"
    environment:
      ARANGO_NO_AUTH: 1
    volumes:
      - ./arangodb3:/var/lib/arangodb3

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM