Guest User

Untitled

a guest
Oct 17th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. SpoofItemSchema.pre('save', function(next){
  2. console.log('pre save on spoof item');
  3. var doc = this;
  4. // find the url_count and increment it by 1
  5. counter.findByIdAndUpdate({_id: 'url_count'}, {$inc: {seq: 1} }, function(error, counter) {
  6. if (error) {
  7. console.log('error in pre save');
  8. return next(error);
  9. }
  10. // set the _id of the urls collection to the incremented value of the counter
  11. doc._id = counter.seq;
  12. doc.created_at = new Date();
  13. next();
  14. });
  15. });
Add Comment
Please, Sign In to add comment