Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. [ { _id: 57682f69feaf405c51fdf144,
  2. email: 'testuser1@testdomain.com',
  3. username: 'testuser' },
  4. { username: 'sevilayha', _id: 5768d36c4c243de7422f681e, __v: 0 } ]
  5.  
  6. // With Mongoose, everything is derived from a Schema. Let's get a reference to it and define our users.
  7. var userSchema = mongoose.Schema({
  8. name: String,
  9. username: { type: String, required: true, unique: true },
  10. password: { type: String, required: true },
  11. admin: Boolean,
  12. location: String,
  13. meta: {
  14. age: Number,
  15. website: String
  16. },
  17. created_at: Date,
  18. updated_at: Date
  19. });
  20.  
  21. // The next step is compiling our schema into a Model.
  22. var User = mongoose.model('User', userSchema);
  23.  
  24. app.get("/", function(req, res) {
  25. var updateQuery = {
  26. date: Date.now()
  27. };
  28. User.findOne({ username: /^sevilayha/ }, function (err, user) {
  29. if (err) return console.error(err);
  30. user.update({
  31. $push: updateQuery,
  32. $set: { size: 'large' },
  33. email: 'test@example.com'
  34. });
  35. res.status(200).json(user);
  36. });
  37. User.find(function (err, users) {
  38. if (err) return console.error(err);
  39. console.log(users);
  40. });
  41.  
  42. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement