es6 spread operator - mongoose result copy es6 spread operator - mongoose result copy mongoose mongoose

es6 spread operator - mongoose result copy


You can use the Mongoose Document.toObject() method. It will return the underlying plain JavaScript object fetched from the database.

const newObject = {...result.toObject(), toto: "toto"};

You can read more about the .toObject() method here.