Guest User

Untitled

a guest
May 24th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. var mongoose = require('mongoose');
  2. var Schema = mongoose.Schema;triggers
  3. var User = require('./UserModel');
  4.  
  5. var PostSchema = new Schema({
  6. 'title' : String,
  7. 'content' : String,
  8. 'date' : Date,
  9. 'tags' : String,
  10. 'userID' : {
  11. type: Schema.Types.ObjectId,
  12. ref: 'User'
  13. }
  14. });
  15.  
  16. PostSchema.post('save', function (doc) {
  17. User.findById(doc.userID,function (err, doc) {
  18. //here you would normally do doc.set and doc.save right? but there's no response object
  19. });
  20. });
  21.  
  22. module.exports = mongoose.model('Post', PostSchema);
Add Comment
Please, Sign In to add comment