2012-01-21 12 views

Respuesta

11

Usted podría hacer

var comment = post.comments.id(my_id); 
comment.author = 'Bruce Wayne'; 

post.save(function (err) { 
    // emmbeded comment with author updated  
}); 
+0

Gracias! funciona para mi. – Erik

+4

Guardar no parece activarse cuando actualizo documentos incrustados, y marcarlo como cambiado tampoco lo invalida. –

12

Se SHAUD ser algo como esto:

YOURSCHEMA.update(
     { _id: "DocumentObjectid" , "ArrayName.id":"ArrayElementId" }, 
     { $set:{ "ArrayName.$.TheParameter":"newValue" } }, 
     { upsert: true }, 
     function(err){ 

     } 
    ); 

En este exemple busco un elemento con un parámetro de identificación, pero podría ser el parámetro _id real del tipo objectId.

Véase también: MongooseJS Doc - Updating Set y Similar SO question

Cuestiones relacionadas