Guest User

Untitled

a guest
Feb 25th, 2019
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. const Schema = new mongoose.Schema({
  2. img: { type: String, ref: 'userRequest' },
  3. name: String,
  4. email: String,
  5. lastname: String,
  6. pass: String,
  7. phonenumber: String,
  8. zipcode: String,
  9. birthdate: String,
  10. friends: []
  11. });
  12.  
  13. var user = mongoose.model('simple-chat', Schema);
  14.  
  15. var friendname;
  16. var friendarr = [];
  17.  
  18. app.get('/userfriendslist', (req, res) => {
  19.  
  20.  
  21. user.find({ name: loginperson }, (err, result) => {
  22. if (err) {
  23. console.log(err);
  24. }
  25. else {
  26. for (var i = 0; i < result.length; i++) {
  27.  
  28. console.log("results length" + result.length)
  29.  
  30. for (var j = 0; j < result[i].friends.length; j++) {
  31. if (result[i].friends[j].friendname != null) {
  32. console.log("result of one" + result[i].friends.length);
  33. friendname = result[i].friends[j].friendname;
  34. console.log("friend list" + friendname);
  35. user.find({ name: friendname }, (err, doc) => {
  36. console.log("total result" + doc);
  37.  
  38.  
  39. friendarr[i] = doc;
  40.  
  41. console.log("insidefriendsarray" +friendarr[i]);
  42. });
  43. }
  44. else {
  45. console.log("No friend found");
  46. }
  47. }
  48. console.log("XXXXXXX"+friendarr[i]);
  49. /* res.send(friendarr[i]); */
  50. }
  51. }
  52. })
  53. });
Add Comment
Please, Sign In to add comment