How do I add temporary properties on a mongoose object just for response, which is not stored in database

Found the answer here: Unable to add properties to js object

I cant add properties on a Mongoose object, I have to convert it to plain JSON-object using the .toJSON() or .toObject() methods.

EDIT: And like @Zlatko mentions, you can also finalize your queries using the .lean() method.

mongooseModel.find().lean().exec()

… which also produces native js objects.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)