title: Nodejs middleware .pre shows not a function
body: <pre><code>    var categoryList = new Referral({categoryList : category});
  
      categoryList.pre('save', function (next) {
          Referral.find({categoryList : category}, function (err, docs) {
              if (!docs.length){
                  next();
              }else{
                  console.log('Data exists: ', category);
                  next(new Error("Data exists!"));
              }
          })
      })
  </code></pre>
  
  <p>Referral is my variable assigned to my schema.
  categoryList is the object </p>
  
  <p>This gives an error </p>
  
  <blockquote>
    <p>TypeError: categoryList.pre is not a function    at
    D:\Aventyn\ClipCare_v2\app\api.js:112:18    at Layer.handle [as
    handle_request]
    (D:\Aventyn\ClipCare_v2\node_modules\express\lib\router\layer.js:95:5)
    at next
    (D:\Aventyn\ClipCare_v2\node_modules\express\lib\router\route.js:131:13)
    at Route.dispatch
    (D:\Aventyn\ClipCare_v2\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request]
    (D:\Aventyn\ClipCare_v2\node_modules\express\lib\router\layer.js:95:5)
    at
    D:\Aventyn\ClipCare_v2\node_modules\express\lib\router\index.js:277:22
    at Function.process_params
    (D:\Aventyn\ClipCare_v2\node_modules\express\lib\router\index.js:330:12)
    at next
    (D:\Aventyn\ClipCare_v2\node_modules\express\lib\router\index.js:271:10)
    at Function.handle
    (D:\Aventyn\ClipCare_v2\node_modules\express\lib\router\index.js:176:3)
    at router
    (D:\Aventyn\ClipCare_v2\node_modules\express\lib\router\index.js:46:12)
    at Layer.handle [as handle_request]
    (D:\Aventyn\ClipCare_v2\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix
    (D:\Aventyn\ClipCare_v2\node_modules\express\lib\router\index.js:312:13)
    at
    D:\Aventyn\ClipCare_v2\node_modules\express\lib\router\index.js:280:7 
    at Function.process_params
    (D:\Aventyn\ClipCare_v2\node_modules\express\lib\router\index.js:330:12)
    at next
    (D:\Aventyn\ClipCare_v2\node_modules\express\lib\router\index.js:271:10)
    at
    D:\Aventyn\ClipCare_v2\node_modules\express\lib\router\index.js:618:15</p>
  </blockquote>