title: Why connect-mongo creates new session for every request?
body: <p>I have two nodejs servers (web-server, socket-server), that are connected to each other by socket.io. On web-service I use express.js and passport.js as authentication middleware.</p>
  
  <p>This is my web-server config:</p>
  
  <pre><code>var express = require('express'),
      mongo = require('mongodb'),
      io = require('socket.io'),
      passport = require('passport'),
      LocalStrategy = require('passport-local').Strategy,
      MongoStore = require('connect-mongo')(express);
  
  app.configure(function () {
      app.use(express.cookieParser());
      app.use(express.methodOverride());
      app.use(express.bodyParser());
      app.use(express.session({
          secret: 'keyboard cat',
          store: new MongoStore({
            db: 'MyDatabase'
          })
      }));
      app.use(passport.initialize());
      app.use(passport.session());
      app.use(app.router);
      app.use(express.static(__dirname + '/htdocs'));
  });
  </code></pre>
  
  <p><strong>When I use connect-mongo, it creates a new session for each http-request.</strong></p>
  
  <p>This element creates with log in request:</p>
  
  <pre><code>{
    "_id" : "UCnXade6Bk6ofOZ+jiEgzyH8",
    "session" : "{\"cookie\":{\"originalMaxAge\":31536000000,\"expires\":\"2014-03-07T13:07:45.703Z\",\"httpOnly\":true,\"path\":\"/\"},\"passport\":{\"user\":\"50cae08806e31ea2e5634e3f\"}}",
    "expires" : new Date("7.3.2014 19:07:45")
  }
  </code></pre>
  
  <p>And this element creates each time, when I press F5, or take socket.</p>
  
  <pre><code>{
    "_id" : "JhypbYFtj1CGOK/ylMhG8+Yk",
    "session" : "{\"cookie\":{\"originalMaxAge\":null,\"expires\":null,\"httpOnly\":true,\"path\":\"/\"},\"passport\":{}}",
    "expires" : new Date("21.3.2013 19:03:38")
  }
  </code></pre>
  
  <p>When web-server takes socket connection, connect-mongo creates new session. There are about 50 new documents per minute.</p>
  
  <p>What could be the reason?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>In the case of updating the page, helped tip to add <code>app.use(express.favicon())</code>.</p>
  
  <p>With sockets question is still actual.</p>
  
  <p>My socket-server code</p>
  
  <pre><code>function sendPortalJSON (portal_id, data, _event) {
      https.get({
          host : ....,
          port : ....,
          path : "/" + _event + "?data=" + encodeURIComponent( JSON.stringify (data))
      }).on('error', function (err) {
  
      });
  }
  ...
  sendPortalJSON(1, agent_data[i].d, "cpu-details");
  </code></pre>
  
  <p>And on web-server:</p>
  
  <pre><code>app.get('/cpu-details', function (req, res) { });
  </code></pre>