Skip to content

findOneAndUpdate return by default original document #2284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
enrychemp opened this issue Oct 7, 2016 · 2 comments · Fixed by #2301
Closed
1 task done

findOneAndUpdate return by default original document #2284

enrychemp opened this issue Oct 7, 2016 · 2 comments · Fixed by #2301

Comments

@enrychemp
Copy link

  • I understand that GitHub issues are not for tech support, but for questions specific to this generator, bug reports, and feature requests.
Item Version
generator-angular-fullstack 4.1.0
Node 6.7.0
npm 3.10.3
Operating System OS X 10.12
Item Answer
Transpiler Babel
Markup / Pug
CSS SCSS
Router ui-router
Client Tests Jasmine
DB MongoDB 3.2.7
Auth Y

report link
Automattic/mongoose#2262

and mongodb
https://docs.mongodb.com/manual/reference/method/db.collection.findAndModify/

export function upsert(req, res) {
  if(req.body._id) {
    delete req.body._id;
  }
  return Thing.findOneAndUpdate(req.params.id, req.body, {upsert: true, setDefaultsOnInsert: true, runValidators: true}).exec()

    .then(respondWithResult(res))
    .catch(handleError(res));
}

modified return saved document

export function upsert(req, res) {
  if(req.body._id) {
    delete req.body._id;
  }
  return Thing.findOneAndUpdate(req.params.id, req.body, {new: true, upsert: true, setDefaultsOnInsert: true, runValidators: true}).exec()

    .then(respondWithResult(res))
    .catch(handleError(res));
}

@Awk34
Copy link
Member

Awk34 commented Oct 7, 2016

Feel free to submit a PR for these sorts of things

@thomsa
Copy link

thomsa commented Oct 11, 2016

👍 +1

aniknafs added a commit to aniknafs/generator-angular-fullstack that referenced this issue Oct 17, 2016
findOneAndUpdate return modified document now instead of original

fixes angular-fullstack#2284
Awk34 pushed a commit that referenced this issue Oct 17, 2016
findOneAndUpdate return modified document now instead of original

fixes #2284
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants