Using lodash cloneDeep() on mongoose result - can't update resulting JSON Using lodash cloneDeep() on mongoose result - can't update resulting JSON mongoose mongoose

Using lodash cloneDeep() on mongoose result - can't update resulting JSON


The method you would use in order to keep mongoose happy with change tracking etc would be using set.

However I highly doubt cloning the object and using set would be something even remotely close to a best practice.

Why not simply create another model? Why circumventing the build in change tracking etc in mongoose by cloning?

You might as well simply use toObject of your new mongoose model ... skip the cloning ... change values etc ... then simply pass that object to a new Model(yourObjectWithChanges) and then save:

var newAlarm = alarm.toObject() ... do your changeslet newAlarmModel = new Model(newAlarm)await newAlarmModel.save()