Guest User

Untitled

a guest
Oct 3rd, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. index: function(req, res) {
  2. User.findOne({
  3. _id: req.params.id
  4. })
  5. .populate({path: "roommates", match: {status: {$eq: "active"}}})
  6. .exec(function(err, user) {
  7. console.log(user.roommates);
  8. })
  9. }
  10.  
  11. [ { _id: 57f2e5e02d58f51a8284bc11,
  12. balance: 0,
  13. requests: [],
  14. status: 'pending' } ]
  15.  
  16. var UserSchema = new Schema({
  17. name: String,
  18. username: {
  19. type: String,
  20. required: [true, "Please enter a username"],
  21. minlength: [6, "Username must be at least 6 characters"],
  22. maxlength: [15, "Username cannot exceed 15 characters"],
  23. unique: true
  24. },
  25. password: {
  26. type: String,
  27. required: [true, "Please enter a password"],
  28. minlength: [6, "Password must be at least 6 characters"],
  29. maxlength: [17, "Password cannot exceed 17 characters"],
  30. },
  31. roommates: [{roommate: {type: Schema.Types.ObjectId, ref: "User", unique: true}, status: {type: String, default: "pending"}, requests: [{type: Schema.Types.ObjectId, ref: "Request"}], balance: {type: Number, default: 0}}]
  32. })
Add Comment
Please, Sign In to add comment