在 ArangoDB 中插入或更新文档因违反约束而失败
Insert or update a document in ArangoDB fails with constraint violated
我想在 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:
以防万一,如果这有任何帮助,我 运行 ArangoDB 服务器本地 Docker 和以下 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 社区的 slack 频道上发布了这个问题,那里的好人指出我从 3.4
开始才引入通过 overwrite 参数的 replace-insert。根据我的 docker 撰写,我的图像指向 arangodb 的 Official Docker Repository 的最新图像,即 3.3.20
.
我被解释说这个 "official" 存储库 (arangodb
) 不一定托管最新的稳定版本的 ArangoDB,它可能需要几天才能可用,我应该指向arangodb/arangodb
.
我调整了我的 docker-compose.yml
文件以使用正确的图像,现在它工作正常。
docker-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!
我想在 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:
以防万一,如果这有任何帮助,我 运行 ArangoDB 服务器本地 Docker 和以下 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 社区的 slack 频道上发布了这个问题,那里的好人指出我从 3.4
开始才引入通过 overwrite 参数的 replace-insert。根据我的 docker 撰写,我的图像指向 arangodb 的 Official Docker Repository 的最新图像,即 3.3.20
.
我被解释说这个 "official" 存储库 (arangodb
) 不一定托管最新的稳定版本的 ArangoDB,它可能需要几天才能可用,我应该指向arangodb/arangodb
.
我调整了我的 docker-compose.yml
文件以使用正确的图像,现在它工作正常。
docker-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!