Skip to content

Instantly share code, notes, and snippets.

@tglines
Created January 14, 2011 06:28
Show Gist options
  • Save tglines/779266 to your computer and use it in GitHub Desktop.
Save tglines/779266 to your computer and use it in GitHub Desktop.
TypeError: Object function (options, callback) {
options = options || {};
var collection = null,
mongoStore = Store.prototype,
url = getConnectionURL(options, callback),
details = parseConnectionURL(url), // mongodb 0.7.9 parser is broken, this fixes it
db = new mongo.Db(details.dbname, new mongo.Server(details.host, details.port, options)),
getCollection = function (db, callback) {
db.collection(options.collection || defaults.collection, function (err, col) {
collection = col;
if (callback) {
callback(null, col);
}
});
};
db.open(function (err) {
if (err) {
throw new Error("Error connecting to " + url);
}
if (details.username && details.password) {
db.authenticate(details.username, details.password, function () {
getCollection(db, callback);
});
} else {
getCollection(db, callback);
}
});
Store.call(mongoStore, options);
/**
* Attempt to fetch session by the given `hash`.
*
* @param {String} hash
* @param {Function} fn
* @api public
*/
mongoStore.get = function (hash, fn) {
collection.findOne({_id: hash}, function (err, data) {
try {
if (data) {
delete data._id;
}
// TODO: fail if expired
fn(null, data);
} catch (exc) {
fn(exc);
}
});
};
/**
* Commit the given `sess` object associated with the given `hash`.
*
* @param {String} hash
* @param {Session} sess
* @param {Function} fn
* @api public
*/
mongoStore.set = function (hash, sess, fn) {
try {
sess._id = hash;
collection.update({_id: hash}, sess, {upsert: true}, function (err, data) {
if (data) {
delete data._id;
}
if (fn) {
fn.apply(this, arguments);
}
});
} catch (exc) {
if (fn) {
fn(exc);
}
}
};
/**
* Destroy the session associated with the given `hash`.
*
* @param {String} hash
* @api public
*/
mongoStore.destroy = function (hash, fn) {
collection.remove({_id: hash}, fn);
};
/**
* Fetch number of sessions.
*
* @param {Function} fn
* @api public
*/
mongoStore.length = function (fn) {
collection.count({}, fn);
};
/**
* Clear all sessions.
*
* @param {Function} fn
* @api public
*/
mongoStore.clear = function (fn) {
collection.drop(fn);
};
/**
* Get the collection
*
* @param
* @api public
*/
mongoStore.getCollection = function (fn) {
return collection;
};
return mongoStore;
} has no method 'get'
at Object.sessionHandle [as handle] (/usr/local/lib/node/.npm/connect/0.5.0/package/lib/connect/middleware/session.js:123:15)
at next (/usr/local/lib/node/.npm/connect/0.5.0/package/lib/connect/index.js:254:23)
at Object.cookieDecoder [as handle] (/usr/local/lib/node/.npm/connect/0.5.0/package/lib/connect/middleware/cookieDecoder.js:32:13)
at next (/usr/local/lib/node/.npm/connect/0.5.0/package/lib/connect/index.js:254:23)
at Object.methodOverride [as handle] (/usr/local/lib/node/.npm/connect/0.5.0/package/lib/connect/middleware/methodOverride.js:51:9)
at next (/usr/local/lib/node/.npm/connect/0.5.0/package/lib/connect/index.js:254:23)
at Object.bodyDecoder [as handle] (/usr/local/lib/node/.npm/connect/0.5.0/package/lib/connect/middleware/bodyDecoder.js:54:13)
at next (/usr/local/lib/node/.npm/connect/0.5.0/package/lib/connect/index.js:254:23)
at Object.handle (/usr/local/lib/node/.npm/express/1.0.0/package/lib/express/server.js:65:5)
at next (/usr/local/lib/node/.npm/connect/0.5.0/package/lib/connect/index.js:254:23)
/usr/local/lib/node/.npm/connect/0.5.0/package/lib/connect/middleware/session.js:66
var secured = store.cookie.secure && (req.connection.secure || req
^
TypeError: Cannot read property 'secure' of undefined
at ServerResponse.writeHead (/usr/local/lib/node/.npm/connect/0.5.0/package/lib/connect/middleware/session.js:66:39)
at /usr/local/lib/node/.npm/connect/0.5.0/package/lib/connect/middleware/errorHandler.js:91:29
at fs:84:13
at node.js:773:9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment