有没有办法自动将UUID分配给CouchDB文档?现在,我必须做两个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?
答案 0 :(得分:1)
创建新文档时,如果您执行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"}