I'm not sure if this is intended or a bug, but schema setters don't seem to run in atomic find-and-modify operations. If it's intended, it's quite a big limitation because I use these almost exclusively throughout the app to perform updates. Is there a page that documents behaviors of find-and-modify when coming to validation, setters etc.
Mongoose version: 4.0.1.
That's by design right now, but definitely a feature worth considering for the future
@vkarpov15 thanks for your response. I've been using Mongoose for a number of projects and I've found myself use atomic operations more and more, to almost exclusively in the current project. Without these, I will have to manually execute setters and validations although they are already declared in the schema, which is kind of defeating the purpose of using Mongoose in the first place. On top of that, with all the new hooks available, I would say it's counter-intuitive that setters and validations aren't automatically executed on atomic operations.
I really hope this will be implemented.
+1
+1
+1
+1
+1
runValidators and/or setDefaultsOnInsert don't apply setters???
+1 for this as well.
Dunno if this is still in the works, but I got around it by only ever writing to mongo in one place and just using my setter manually. I passed this as the second argument to findOneAndUpdate
{
$set: {
access_token: encrypt(access_token),
name: name
}
}
+1
Use the runSettersOnQuery
to opt in to this behavior, we'll have it on by default for 5.0 :+1:
Going to close this in favor of #5340. Please follow that issue for more updates, but the plan is to turn this behavior on by default for 5.0.