Consider this schema:
var UserSchema = new Schema({
...
user_id: {type:String},
previous_selection: {type:String},
current_selection: {type:String}
});
I need to write a function, which will update the value of previous_selection
with the value of current_selection
for the given user_id
.
Is there any way of doing this with findOneAndUpdate
?
Something like -
MyModel.findOneAndUpdate(
{ user_id: id },
{ $set: {"previous_selection": current_selection }},
{},
callback
);
Or is there a better way to implement this? Will I have to do a find()
and then update?