Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melissamarima/b6ed4a3570738c1636a3 to your computer and use it in GitHub Desktop.
Save melissamarima/b6ed4a3570738c1636a3 to your computer and use it in GitHub Desktop.
// models/Post.js mongoose schema for mongoDB
PostSchema.methods.upvote = function(cb) {
this.upvotes += 1;
this.save(cb);
};
// Now we create the route in our index.js:
router.put('/posts/:post/upvote', function(req, res, next) {
req.post.upvote(function(err, post){
if (err) { return next(err); }
res.json(post);
});
});
// source https://thinkster.io/mean-stack-tutorial#getting-user-input-enable-upvoting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment