Guest User

Untitled

a guest
Jan 10th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. var userSchema = new mongoose.Schema({
  2. local:{
  3. localId: {type:Number},
  4. username:{type:String},
  5. password: {type:String},
  6. email:{type:String}
  7. },
  8. facebook:{
  9. facebookId: {type:Number},
  10. email:{type:String},
  11. username:{type:String},
  12. password: {type:String}
  13. },
  14. twitter:{
  15. twitterId: {type:Number},
  16. username:{type:String},
  17. password: {type:String},
  18. email:{type:String}
  19.  
  20. }
  21. });
  22.  
  23. User.findOneAndUpdate({$or: [
  24. {'local.username': username }, // 'or' condition works perfect
  25. { 'facebook.username': username },
  26. { 'twitter.username': username },
  27. ]},{
  28. email:req.body.email // doesn't work...here i don't know what to do...
  29. },function(err, user) {
  30. if(err){console.log(err);}
  31. if(!user){
  32. console.log('cannot find user');
  33. }
  34. if(user){
  35. console.log(user);
  36. return res.send(JSON.stringify(user));
  37.  
  38. }
  39. });
  40.  
  41. User.findOneAndUpdate({$or: [
  42. {'local.username': username }, // 'or' condition works perfect
  43. { 'facebook.username': username },
  44. { 'twitter.username': username },
  45. ]},{
  46. $set:{email:req.body.email} // doesn't work...here i don't know what to do...
  47. },function(err, user) {
  48. if(err){console.log(err);}
  49. if(!user){
  50. console.log('cannot find user');
  51. }
  52. if(user){
  53. console.log(user);
  54. return res.send(JSON.stringify(user));
  55.  
  56. }
  57. });
Add Comment
Please, Sign In to add comment