Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. var mongoose = require('mongoose');
  2.  
  3. var PostsOfTheWeekSchema = new mongoose.Schema({
  4. sunday: {
  5. posts: [{}],
  6. date: Date
  7. },
  8. monday: {
  9. posts: [{}],
  10. date: Date
  11. },
  12. tuesday: {
  13. posts: [{}],
  14. date: Date
  15. },
  16. wednesday: {
  17. posts: [{}],
  18. date: Date
  19. },
  20. thursday: {
  21. posts: [{}],
  22. date: Date
  23. },
  24. friday: {
  25. posts: [{}],
  26. date: Date
  27. },
  28. saturday: {
  29. posts: [{}],
  30. date: Date
  31. },
  32. });
  33.  
  34. module.exports = mongoose.model('PostsOfTheWeek', PostsOfTheWeekSchema);
  35.  
  36. router.get('/postsOfTheDay', function (req, res, next) {
  37. PostsOfTheWeek.find({}).populate({path: 'posts', populate: {path: 'post', model: 'Post'}}).exec(function (err, posts) {
  38. if (err) { return next(err); }
  39.  
  40. res.json(posts);
  41. });
  42. });
  43.  
  44. {
  45. "_id": "599a5a529f5cee12bbeb7737",
  46. "__v": 0,
  47. "saturday": {
  48. "posts": [],
  49. },
  50. "friday": {
  51. "posts": [],
  52. },
  53. "thursday": {
  54. "posts": [],
  55. },
  56. "wednesday": {
  57. "posts": [],
  58. },
  59. "tuesday": {
  60. "posts": [],
  61. },
  62. "monday": {
  63. "posts": [],
  64. },
  65. "sunday": {
  66. "date": "2017-08-21T03:58:10.000Z",
  67. "posts": [
  68. {
  69. "name": "Music",
  70. "post": "599a298f5bdc6e107a8a5a48"
  71. },
  72. {
  73. "name": "News",
  74. "post": "599a134189c3150fe701d384"
  75. }
  76. ],
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement