title: Cannot read property 'insert' of undefined when trying to put data in MongoDB
body: <p>I'm getting this error: "Cannot read property 'insert' of undefined" when trying to insert data into a database. The error shows on:</p>
  
  <p><strong>db.coordinates.<em>insert</em>({ "x" : "data.x", "y" : "data.y"})</strong></p>
  
  <p>Database name - "node5"
  Collection name - "coordinates"</p>
  
  <pre><code>// Including libraries
  var app = require('http').createServer(handler);
  var io = require('socket.io').listen(app);
  var static = require('node-static'); // for serving files
  
  //db connection
  
  var MongoClient = require('mongodb').MongoClient;
  var assert = require('assert');
  var ObjectId = require('mongodb').ObjectID;
  
  var mongo = require('mongodb');
  var monk = require('monk');
  var db = monk('localhost:27017/node5');
  
  
  
  var url = 'mongodb://localhost:27017/node5';
  MongoClient.connect(url, function(err, db) {
    assert.equal(null, err);
    console.log("Connected correctly to server.");
    db.close();
  });
  
  // This will make all the files in the current folder
  // accessible from the web
  var fileServer = new static.Server('./');
  
  // This is the port for our web server.
  // you will need to go to http://localhost:8080 to see it
  app.listen(8080);
  
  // If the URL of the socket server is opened in a browser
  function handler(request, response) {
      request.addListener('end', function () {
          fileServer.serve(request, response);
      }).resume();
  }
  
  // Delete this row if you want to see debug messages
  io.set('log level', 1);
  
  
  // Listen for incoming connections from clients
  io.sockets.on('connection', function (socket) {
      // Listen for mouse move events
      socket.on('post', function (data) {
          console.log('posted');
          console.log(data);
          socket.broadcast.emit('posted', data); // Broadcasts event to everyone except originating client
          db.coordinates.insert({ "x" : "data.x", "y" : "data.y"})
      });
  });
  </code></pre>
  
  <p>When writing an answer, please note that I'm new to node.js and I might not understand if you tell the answer in a complex way:)</p>