0

我正在尝试使用 Restheart API 删除一个集合。

$http DELETE 127.0.0.1:8080/testDB/testCollection

但我得到了错误:

"The collection's ETag must be provided using the 'If-Match' header."

如果我使用 GET:

http GET 127.0.0.1:8080/testDB/testCollection

我可以从最后一个 GET 请求响应中看到 etag 并将其手动添加到 If-Match 标头以删除集合。

但是我不明白我将如何检索给定集合(即 testCollection)的 _etag。

我的最终目标是从使用 apache http commons 作为 REST API 客户端的 java 应用程序中删除该集合。因此,Java 中的示例是最受欢迎的。

4

1 回答 1

1

只获取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
于 2017-02-22T09:38:49.983 回答