You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've encountered an error while trying to update entities.
This is the generated code: findOneAndUpdate(req.params.id, req.body, {upsert: true, setDefaultsOnInsert: true, runValidators: true}).exec()
It was always updating the first element in the collection, because it's not specified what field it should compare.
As in the mongoose documentation: query.findOneAndUpdate(conditions, update, options)
The condition is not really a condition in the generated code.
I had to change it to the code below and it started to work as expected entity.findOneAndUpdate({"_id" : req.params.id }, req.body, {upsert: true, setDefaultsOnInsert: true, runValidators: true}).exec()
Has anybody encountered this problem, or is it written in some documentation that this is what we have to do if we want it to work? I haven't found it in any docs though.
The text was updated successfully, but these errors were encountered:
is certainly incorrect; the first call argument must be a condition and in this case should be as you show in the second statement. It is annoying that mongoose doesn't detect this and treat it as an error.
Hi!
I've encountered an error while trying to update entities.
This is the generated code:
findOneAndUpdate(req.params.id, req.body, {upsert: true, setDefaultsOnInsert: true, runValidators: true}).exec()
It was always updating the first element in the collection, because it's not specified what field it should compare.
As in the mongoose documentation:
query.findOneAndUpdate(conditions, update, options)
The condition is not really a condition in the generated code.
I had to change it to the code below and it started to work as expected
entity.findOneAndUpdate({"_id" : req.params.id }, req.body, {upsert: true, setDefaultsOnInsert: true, runValidators: true}).exec()
Has anybody encountered this problem, or is it written in some documentation that this is what we have to do if we want it to work? I haven't found it in any docs though.
The text was updated successfully, but these errors were encountered: