8
8
var Store = require ( 'connect' ) . session . Store
9
9
, mongo = require ( 'mongodb' )
10
10
, _collection = null
11
- , _default = function ( callback ) {
12
- callback = typeof ( callback ) === 'function' ? callback : function ( ) { } ;
13
- return callback ;
14
- }
15
11
, _defaults = { host : '127.0.0.1' , port : 27017 , dbname : 'dev' , collection : 'sessions' , reapInterval : 60 * 1000 } ;
16
12
13
+ function _default ( callback ) {
14
+ callback = typeof ( callback ) === 'function' ? callback : function ( ) { } ;
15
+ return callback ;
16
+ }
17
+
17
18
/**
18
19
* Initialize MongoStore with the given `options`.
19
20
*
@@ -81,7 +82,7 @@ var MONGOSTORE = module.exports = function MongoStore(options, callback) {
81
82
} , options . reapInterval || _defaults . reapInterval , this ) ; // _defaults to each minute
82
83
}
83
84
84
- if ( server_config . isConnected ( ) ) {
85
+ if ( server_config . connected ) {
85
86
authenticateAndGetCollection ( callback ) ;
86
87
} else {
87
88
server_config . connect ( db , function ( err ) {
@@ -109,9 +110,8 @@ MONGOSTORE.prototype.get = function (sid, cb) {
109
110
_collection . findOne ( { _id : sid } , function ( err , data ) {
110
111
try {
111
112
if ( data ) {
112
- var sess =
113
- typeof data . session === 'string' ? JSON . parse ( data . session )
114
- : data . session ;
113
+ var sess = typeof data . session === 'string' ? JSON . parse ( data . session )
114
+ : data . session ;
115
115
cb ( null , sess ) ;
116
116
} else {
117
117
cb ( ) ;
@@ -126,29 +126,21 @@ MONGOSTORE.prototype.get = function (sid, cb) {
126
126
/**
127
127
* Commit the given `sess` object associated with the given `sid`.
128
128
*
129
- * With connect-session, `sess.cookie` has a getter `data`, and if we
130
- * store sess.cookie.data in the DB, problems occur. Run sess through
131
- * JSON.stringify(), which strips out the getter.
132
- *
133
129
* @param {String } sid
134
130
* @param {Session } sess
135
131
* @param {Function } cb
136
132
* @api public
137
133
*/
138
134
MONGOSTORE . prototype . set = function ( sid , sess , cb ) {
139
135
cb = _default ( cb ) ;
140
- try {
141
- var update = { _id : sid , session : JSON . parse ( JSON . stringify ( sess ) ) } ;
142
- if ( sess && sess . cookie && sess . cookie . expires ) {
143
- update . expires = Date . parse ( sess . cookie . expires ) ;
144
- }
145
-
146
- _collection . update ( { _id : sid } , update , { upsert : true } , function ( err , data ) {
147
- cb . apply ( this , arguments ) ;
148
- } ) ;
149
- } catch ( exc ) {
150
- cb ( exc ) ;
136
+ var update = { _id : sid , session : JSON . stringify ( sess ) } ;
137
+ if ( sess && sess . cookie && sess . cookie . expires ) {
138
+ update . expires = Date . parse ( sess . cookie . expires ) ;
151
139
}
140
+
141
+ _collection . update ( { _id : sid } , update , { upsert : true } , function ( err , data ) {
142
+ cb . apply ( this , arguments ) ;
143
+ } ) ;
152
144
} ;
153
145
154
146
/**
0 commit comments