只获取etagGET 127.0.0.1:8080/testDB/testCollection?pagesize=0
,您会在其属性之间和Etag 响应标头中找到它
http -a a:a 127.0.0.1:8080/db/coll?pagesize=0
HTTP/1.1 200 OK
...
ETag: 58653f6b2d174c09c590262a**
{
"_embedded": [],
"_etag": {
"$oid": "58653f6b2d174c09c590262a"
},
"_id": "coll",
"_returned": 0,
}
另请注意,如果发生冲突,尝试删除集合会返回 Etag 响应标头
http -a a:a DELETE 127.0.0.1:8080/db/coll
HTTP/1.1 409 Conflict
...
ETag: 58653f6b2d174c09c590262a
{
"http status code": 409,
"http status description": "Conflict",
"message": "The collection's ETag must be provided using the 'If-Match' header."
}
最后,您可以在配置文件中设置 Etag 检查行为。默认情况下仅在 DELETE /db 和 /coll 上检查 etag,但可以对任何写入请求启用(例如,以避免所谓的幽灵写入问题)
来自 conf 文件:
#### ETag policy
# the following configuration defines the default etag check policy
# the policy applies for dbs, collections (also applies to file buckets) and documents
# valid values are REQUIRED, REQUIRED_FOR_DELETE, OPTIONAL
etag-check-policy:
db: REQUIRED_FOR_DELETE
coll: REQUIRED_FOR_DELETE
doc: OPTIONAL