AllenYuan

tags endpoint

May 19th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var router = require('express').Router();
  2. var mongoose = require('mongoose');
  3. var Article = mongoose.model('Article');
  4.  
  5. // grab the distinct tags used, sorted in descending order of frequency
  6. router.get('/', function(req, res, next) {
  7.   Article.find().distinct('tagList').then(function(tags){
  8.     return res.json({tags: tags});
  9.   }).catch(next);
  10. });
  11.  
  12. module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment