title: Insert data in mongoDB database from node.js
body: <p>Context: Want to insert data in mongoDB database from node.js</p>
  
  <p>Problem Statement: I am trying to insert data in the mongoDB database but thrown an error. Cant find it.</p>
  
  <p>Present Output: Reference error</p>
  
  <p>Attach Code: </p>
  
  <p><strong>filter.js</strong></p>
  
  <pre><code>    var server = require('http'),
      express = require('express'),
      http = require('http'),
      fs = require('fs');
      filter = express(),
  
      io = require('socket.io'),
      mongoose = require('mongoose');
  
      mongoose.connect('mongodb://localhost/filter_CheckBoxSchema', function(err){
      if(err){
          console.log(err);
      } else{
          console.log('Connected to mongodb!');
      }
  });
  
  
      http.createServer(function(request, response) {  
          response.writeHeader(200, {"Content-Type": "text/html"});  
          response.write(html);  
          response.end();  
      }).listen(8000);
  
      var filter_CheckBoxSchema = mongoose.Schema({
      name: String,
      type: Boolean,
      created: {type: Date, default: Date.now}
      });
  
      var Filter = mongoose.model('Store', filter_CheckBoxSchema);
  
      fs.readFile('./index.html', function (err, html) {
      if (err) {
          throw err; 
      } 
  
      new Filter({
          name: request.body.name,
          type: request.body.gender,
  
      }).save(function(err, doc){
          if(err) 
          {
              throw err;
          }
          else
          response.send('Successfully inserted!!!');
      });
  });
  </code></pre>
  
  <p><strong>index.html</strong></p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Please enter your details&lt;/title&gt;
  &lt;/head&gt;
      &lt;body&gt;
      &lt;h3&gt;Please enter your details&lt;/h3&gt;
      &lt;p&gt;Please register below!!!&lt;/p&gt;
  
      &lt;form action="filter.js" method="POST"&gt;
      Name: &lt;input type="text" name="Name" /&gt;
      &lt;br /&gt;&lt;p&gt;&lt;/p&gt;
      Gender:
      &lt;br /&gt; 
      &lt;input type="radio" name="gender"/&gt; Male
      &lt;br /&gt;
      &lt;input type="radio" name="gender"/&gt; Female
      &lt;p&gt;&lt;/p&gt;
      Interest: (Check all that apply)
      &lt;p&gt;
      &lt;/p&gt;
      &lt;input type="checkbox" name="breakfast"/&gt; Breakfast
      &lt;br/&gt;
      &lt;input type="checkbox" name="Lunch"/&gt; Lunch
      &lt;br /&gt;
      &lt;input type="checkbox" name="Evening Snacks"/&gt; Evening Snacks
      &lt;br /&gt;
      &lt;input type="checkbox" name="Dinner"/&gt; Dinner
      &lt;br /&gt;
      &lt;p&gt;&lt;/p&gt;
      &lt;input type="submit" name="submit" value="Register!!!" /&gt;
      &lt;/form&gt;
      &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>C:\node\people discovery app&gt;node filter.js
  Connected to mongodb!
  
  C:\node\people discovery app\filter.js:152
                  name: request.body.name,
                        ^
  ReferenceError: request is not defined
      at C:\node\people discovery app\filter.js:152:9
      at fs.js:271:14
      at Object.oncomplete (fs.js:107:15)
  </code></pre>