var fs = require('fs'),
    striptags = require('striptags'),
    request = require('request'),
    mongoosastic = require('mongoosastic'),
    findOrCreate = require('mongoose-findorcreate'),
    mongoose = require('mongoose'),
    Schema = mongoose.Schema;

var BookmarkSchema = new Schema({
  url: {
    type: String,
    required: true,
    unique: true
  },
  content: {
    type: String,
    required: true,
    es_indexed: true
  }
});

BookmarkSchema.plugin(mongoosastic);
BookmarkSchema.plugin(findOrCreate);


BookmarkSchema.pre('save', function(next) {
  request(self.url, function(err, res, body) {
    if (err) {
      console.log(err);
    }
    tagless = striptags(body);
    spaceless = tagless.replace(/\s+/g, ' ');
    self.content = spaceless;
  });
  next();
});

module.exports = mongoose.model('Bookmark', BookmarkSchema);
@@ -377,37 +377,39 @@
     type: String
-,
 %0A   
+ //
  required: true,
@@ -407,21 +407,23 @@
 ed: true
-,
 %0A   
+ //
  es_inde
@@ -516,17 +516,16 @@
 eate);%0A%0A
-%0A
 Bookmark
@@ -566,101 +566,181 @@
 %7B%0A  
-request(self.url, function(err, res, body) %7B%0A    if (err) %7B%0A      console.log(err);%0A    %7D%0A   
+this.content = this.assignContent(this.url);%0A  next();%0A%7D);%0A%0ABookmarkSchema.methods = %7B%0A  assignContent: function(url) %7B%0A    request(url, function(err, res, body) %7B%0A      var
  tag
@@ -767,16 +767,22 @@
 y);%0A    
+  var 
 spaceles
@@ -823,22 +823,16 @@
     
-self.content =
+  return
  spa
@@ -843,16 +843,18 @@
 ss;%0A
+  
   %7D);%0A  
 next
@@ -849,26 +849,19 @@
   %7D);%0A  
-next();
+%7D
 %0A%7D
-)
 ;%0A%0Amodul

refactor pre save method and set content function