2015-11-06 124 views
-1

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

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?

回答

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"}