title: Express load Session from Mongo with session_id
body: <p>Heylo,</p>
  
  <p>I'm building a (semi) REST API with Nodejs/Express as back and Phonegap/Cordova as front.
  For backend i'm using <code>express</code> with <a href="https://github.com/kcbanner/connect-mongo" rel="nofollow"><code>connect-mongo</code></a> and <a href="http://mongoosejs.com/" rel="nofollow"><code>mongoose</code></a> as following :</p>
  
  <pre><code>express.cookieParser(),
  express.session({
      secret: nconf.get('session:salt'),
      store: new mongoStore({url: nconf.get('database').url})
  }),
  </code></pre>
  
  <p>for session validation on node i've create the following function inside my <code>route.js</code> file</p>
  
  <pre><code>var authenticate = function (req, res, next) {
  
  if (req.session.user)
      next();
  else
      res.error('access is not authentication');
  }
  </code></pre>
  
  <p><strong>Unfortunately PhoneGap and Cordova do not support cookies out of the box</strong> so i use <code>localStorage</code>
  to store session_id and wrap every server call to aggregate it to the url params.</p>
  
  <p>Is there any elegant way to pre-load the session from mongoDB inside my <code>authenticate</code> function by the 'session_id' param without creating a <code>Schema</code> for the session collection and try querying it with mongoose?</p>
  
  <p>Cheers,</p>
  
  <p>-PK.</p>