2011-07-12 11 views

Respuesta

8

Usted puede, sin embargo, la solución no es perfecta.

ya conoce el documento _id en la función de actualización. O se está calculando usted mismo, o el uso de la entrada del usuario, o si desea dejar que CouchDB producir un ID de forma automática, a continuación, utilizar el valor 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}]); 
} 

Por desgracia, no se sabe la _rev en la función de presentación. Sin embargo, CouchDB lo enviará al cliente en el encabezado HTTP X-Couch-Update-NewRev.

Por ejemplo:

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} 
Cuestiones relacionadas