Monday, 8 May 2017

Mongoose - save document Object.assign

I have a mongoose document, and i want to update many fields on it with another object. something like

Model.findById(_id, function (err, doc){
    var updateData = {...data}

    // i do not want to do 
    doc.foo = data.foo;
    doc.bar = data.bar;

    // i need something like
    doc.save(updateData)
    // or
    doc.update(updateData)
    // or
    doc = {...doc, ...updateData}
    doc.save();

});

the updateData is a object with all the data i need to update in the doc.

didn't found any doc related, the closest was a find one and update...



via Maxwell s.c

No comments:

Post a Comment