你可以,但解决方案并不完美.
您已经知道_id更新功能中的文档.您要么自己计算,要么使用用户输入,或者如果您希望让CouchDB自动生成ID,请使用该req.uuid值.
function(doc, req) {
// An example _update function.
var id;
id = "Whatever"; // Pick one yourself, or...
id = req.query.id; // Let the user specify via ?id=whatever, or...
id = req.body; // Let the user specify via POST or PUT body, or...
id = req.uuid; // Use a random UUID from CouchDB
var doc = {"_id":id, "other_stuff":"Whatever other data you have"};
log("Document _id will be: " + doc._id);
return([doc, {json: {"success":true, "doc":doc}]);
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,你不知道_revshow功能.但是,CouchDB会将其发送到HTTP标头中的客户端X-Couch-Update-NewRev.
例如:
HTTP/1.1 201 Created
X-Couch-Update-NewRev: 1-967a00dff5e02add41819138abb3284d
Server: CouchDB/1.1.0 (Erlang OTP/R14B03)
Date: Tue, 12 Jul 2011 06:09:34 GMT
Content-Type: application/json
Content-Length: 14
{"stuff":true}
Run Code Online (Sandbox Code Playgroud)