CouchDB 从 UUID 请求中减少 Web 请求

CouchDB Reducing Web Requests from UUID Requests

有没有办法自动为 CouchDB 文档分配 UUID?现在,我必须执行两个 Web 请求才能在 CouchDB 中创建一个新字段 - 如果可能,我想将其减少到一个。

curl -X GET http://127.0.0.1:5984/_uuids
curl -X PUT http://127.0.0.1:5984/albums/6e1295ed6c29495e54cc05947f18c8af \
 -d '{"_rev":"1-2902191555","title":"There is Nothing Left to Lose","artist":"Foo Fighters","year":"1997"}'

如何将这两个请求合并为一个 PUT?

创建新文档时,如果您执行 POST 而不是 PUT,CouchDB 将为您填写 _id。确保在执行 POST.

时将 Content-Type 设置为 application/json
$curl -X POST http://127.0.0.1:5984/albums/ \
>  -H "Content-Type: application/json" \
>  -d '{"title":"There is Nothing Left to Lose","artist":"Foo      Fighters","year":"1997"}'
{"ok":true,"id":"41af96d0685bf6535885685c9732055e","rev":"1-7a4ee0b846c0d1cb6308d0769ef041bf"}