Guest User

Untitled

a guest
Oct 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. var userSchema = new mongoose.Schema({
  2. firstname: String,
  3. surname: String,
  4. email: String,
  5. });
  6.  
  7. var appointmentSchema = new mongoose.Schema({
  8. userID: String,
  9. type: Number,
  10. time: Date
  11. });
  12.  
  13. Appointment.aggregate([
  14. {
  15. $match: {"type": 1}
  16. },
  17. {
  18. $lookup:{
  19. from: "users",
  20. localField: "userID",
  21. foreignField: "_id",
  22. as: "appointmentUser"
  23. }
  24. }], function(err,foundAppointmentUser) {
  25. if(err){
  26. console.log(err);
  27. } else {
  28. console.log(foundAppointmentUser);
  29. }
  30. });
  31.  
  32. {
  33. "_id": {
  34. "$oid": "5bcc8eac7ac5980bfa365183"
  35. },
  36. "userID": "5bb4d1945480e60771ccde5a",
  37. "type": 1,
  38. "time": {
  39. "$date": "2018-10-22T10:00:00.000Z"
  40. },
  41. "__v": 0
  42. }
  43.  
  44. {
  45. "_id": {
  46. "$oid": "5bb4d1945480e60771ccde5a"
  47. },
  48. "firstname": "Stu",
  49. "surname": "Test 999",
  50. "email": "stu@stu.com",
  51. "created": {
  52. "$date": "2018-10-03T14:26:28.815Z"
  53. },
  54. "__v": 0
  55. }
  56.  
  57. [ { _id: 5bcc8eac7ac5980bfa365183,
  58. userID: '5bb4d1945480e60771ccde5a',
  59. type: 1,
  60. time: 2018-10-22T10:00:00.000Z,
  61. __v: 0,
  62. appointmentUser: [] } ]
Add Comment
Please, Sign In to add comment