Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. var UserSchema = mongoose.Schema({
  2. username: {
  3. type: String,
  4. index: true,
  5. required: true,
  6. unique: true
  7. },
  8. password: {
  9. type: String,
  10. required: true
  11. },
  12. email: {
  13. type: String,
  14. required: true,
  15. lowercase: true
  16. },
  17. emailVerified: {
  18. type: Boolean,
  19. default: false
  20. },
  21. info: {
  22. name: {
  23. givenName: String,
  24. familyName: String,
  25. },
  26. address: {
  27. street: String,
  28. city: String,
  29. state: String,
  30. zipCode: String
  31. },
  32. primaryPhone: String,
  33. cellPhone: String,
  34. website: String,
  35. licenseNumber: String,
  36. title: String,
  37. company: String
  38. },
  39. avatar: {
  40. type: String,
  41. default: '/images/avatar/default/contacts-128.png'
  42. },
  43. friends: [{ type: ObjectId, ref: User }],
  44. friendRequests: [{ type: ObjectId, ref: User }]
  45. });
  46.  
  47. module.exports.search = function(searchValue, callback) {
  48. var searchValue = new RegExp(`^${searchValue}`, 'i');
  49. var query = {
  50. $or: [
  51. {username: searchValue},
  52. {email: searchValue}
  53. // {givenName condition here...}
  54. ]
  55. }
  56.  
  57. User.find(query, callback).limit(10);
  58. }
  59.  
  60. {info.name.givenName: searchValue}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement