2015-11-06 126 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"}