Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SpoofItemSchema.pre('save', function(next){
- console.log('pre save on spoof item');
- var doc = this;
- // find the url_count and increment it by 1
- counter.findByIdAndUpdate({_id: 'url_count'}, {$inc: {seq: 1} }, function(error, counter) {
- if (error) {
- console.log('error in pre save');
- return next(error);
- }
- // set the _id of the urls collection to the incremented value of the counter
- doc._id = counter.seq;
- doc.created_at = new Date();
- next();
- });
- });
Add Comment
Please, Sign In to add comment