These are chat archives for Automattic/mongoose

Apr 2018
Martin Puza
Apr 09 2018 18:22
hey guys! any idea how i can overwrite an object with findOneAndUpdate, but keep a single old property (ie. the password hash)? or the other way arround, delete all other properties than the ones passed without overwriting the object?
the pre-findAndUpdate is - i think - synchronous and the after-findAndUpdate doesnt return the old field, so I'm kind of out of ideas ^^
Martin Puza
Apr 09 2018 18:43
of course pre is asynchronous and i could do: const foundPassword = await model.findOne({id: this.getUpdate().id}).select('password') and then append that to the update; but that doesn't seem very... optimal.
Apr 09 2018 20:54
@zaubara when you call findOneAndUpdate without passing it { new: true } it should return the previous version of the document.