--
You received this message because you are subscribed to the Google Groups "Express" group.
To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.
con...@1.0.3
connect...@0.1.1
exp...@2.0.0beta
mon...@0.9.1
Node 0.4.2.
Configuration Code:
var MongoStore = require('connect-mongodb');
// Setup
var app = module.exports = express.createServer();
app.configure(function() {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({
secret: settings.secret,
store: new MongoStore({dbname: 'uwsched'})
}));
app.use(app.router);
app.use(express.compiler({ src: __dirname + '/public', enable: ['less'] }));
app.use(express.static(__dirname + '/public'));
});
Traceback:
6 Mar 04:39:48 - [ERROR] TypeError
TypeError: Cannot set property data of #<Object> which has only a getter
at Object.merge
(/home/kcbanner/local/node/lib/node/.npm/connect/1.0.3/package/lib/utils.js:55:14)
at Object.Cookie
(/home/kcbanner/local/node/lib/node/.npm/connect/1.0.3/package/lib/middleware/session/cookie.js:26:22)
at /home/kcbanner/local/node/lib/node/.npm/connect/1.0.3/package/lib/middleware/session.js:316:23
at /home/kcbanner/local/node/lib/node/.npm/connect-mongodb/0.1.1/package/lib/connect-mongodb.js:133:9
at [object Object].<anonymous>
(/home/kcbanner/local/node/lib/node/.npm/mongodb/0.9.1/package/lib/mongodb/collection.js:447:35)
at [object Object].emit (events.js:45:17)
at [object Object].<anonymous>
(/home/kcbanner/local/node/lib/node/.npm/mongodb/0.9.1/package/lib/mongodb/db.js:83:12)
at [object Object].emit (events.js:42:17)
at Socket.<anonymous>
(/home/kcbanner/local/node/lib/node/.npm/mongodb/0.9.1/package/lib/mongodb/connection.js:82:16)
at Socket.emit (events.js:42:17)
As Tj mentioned, most likely a compatibility issue. Going to look into
that next.
-Casey
I'm having this same problem, except on GET requests as well.
con...@1.0.3
connect...@0.1.1exp...@2.0.0beta
mon...@0.9.1
--
You received this message because you are subscribed to the Google Groups "Express" group.
To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.
Hey all,
Update, I got connect-mongodb to run without creating errors in the console (albeit not working yet).
In /usr/local/lib/node/connect-mongodb/lib/ (assuming that’s you’re path), changed the set method:
mongoStore.set = function (hash, sess, fn) {
try {
var maxAge = sess.cookie.maxAge,
ttl = 'number' == typeof maxAge
? maxAge / 1000 | 0
: oneDay
, sessd = JSON.stringify(sess);
sess._id = hash;
//console.log(hash)
collection.update({_id: hash}, [ttl,sessd], {upsert: true}, function (err, data) {
if (data) {
delete data._id;
//console.log('data');
}
if (fn) {
//console.log('fn');
fn.apply(this, arguments);
}
});
} catch (exc) {
if (fn) {
fn(exc);
}
}
};
Although I don’t think it changes much, I tried editing the get method to resemble the connect-redis version:
mongoStore.get = function(hash,fn) {
collection.findOne({_id: hash}, function(err,data) {
try {
if(!data) return fn();
fn(null,JSON.parse(data.toString()));
} catch (err) {
fn(err);
}
});
};
After running with mongostore, I was able to log the hash to the console and confirm that it matched the hash inside of the cookie as well as the expiration date. It’s still not working though as I’m not able to access the session in the app, tried rendering the id of something I set in the session to a view but it’s coming up as undefined. I’ll hack at it more tomorrow.
Hope this helps,
-Anthony C
I have a replacement ready here: https://github.com/kcbanner/connect-mongo
Just finished the first iteration, so docs are coming soon. However,
there are tests for each method of the store.
The major pitfall with the old library was that it was trying to save
the session object directly to the database, however Connect assumes
that it will be JSON.stringify()ed first. So, more data fields than
Connect intended were making it into the DB, and this was causing
merge to barf when the session was eventually loaded. Basically I just
JSON.stringify the session and put that into a mongo document. This
kinda feels kludgy, but it has the benefit of making this library
future-proof for changes to the structure of sessions.
Let me know what you think. I'll put it into npm when I have time (very soon).
-Casey