Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>in the end i'm using a bit of every answer that was given before:</p> <ul> <li>i switched from connect-mongodb to connect-mongo module</li> <li>i'm using a general conf object to store my configuration data</li> <li>there are two db connections because it's easier to handle for me (maybe changed later on, if/when a new version of mongoose/express comes out)</li> </ul> <p>requirements:</p> <pre><code>var express = require('express'), MongoStore = require('connect-mongo')(express), mongo = require('mongoose'); </code></pre> <p>conf object:</p> <pre><code>var conf = { db: { db: 'myDb', host: '192.168.1.111', port: 6646, // optional, default: 27017 username: 'admin', // optional password: 'secret', // optional collection: 'mySessions' // optional, default: sessions }, secret: '076ee61d63aa10a125ea872411e433b9' }; </code></pre> <p>then i can configure it like this:</p> <pre><code>app.configure(function(){ // ... app.use(express.cookieParser()); app.use(express.session({ secret: conf.secret, maxAge: new Date(Date.now() + 3600000), store: new MongoStore(conf.db) })); // important that this comes after session management app.use(app.router); // ... }); </code></pre> <p>and finally connect to mongodb a second time using mongoose:</p> <pre><code>var dbUrl = 'mongodb://'; dbUrl += conf.db.username + ':' + conf.db.password + '@'; dbUrl += conf.db.host + ':' + conf.db.port; dbUrl += '/' + conf.db.db; mongo.connect(dbUrl); mongo.connection.on('open', function () { app.listen(3000); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload