Permalink
Browse files

Added support for passing existing MongoDB Objects for DB connectivity

  • Loading branch information...
1 parent bfc03e8 commit 36231c85f0cba6bb5e77a08bdb2ec5a5a3ca1fdf @hillct hillct committed Aug 25, 2012
Showing with 8 additions and 7 deletions.
  1. +2 −2 Readme.md
  2. +6 −5 lib/connect-mongo.js
View
@@ -14,7 +14,7 @@ via npm:
## Options
- - `db` Database name
+ - `db` Database name OR fully instantiated node-mongo-native object
- `collection` Collection (optional, default: `sessions`)
- `host` MongoDB server hostname (optional, default: `127.0.0.1`)
- `port` MongoDB server port (optional, default: `27017`)
@@ -86,4 +86,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -77,17 +77,18 @@ module.exports = function(connect) {
if(!options.db) {
throw new Error('Required MongoStore option `db` missing');
- }
-
- this.db = new mongo.Db(options.db,
+ }else if(typeof options.db == "object"){
+ this.db = options.db; // Assume it's an instantiated DB Object
+ }else{
+ this.db = new mongo.Db(options.db,
new mongo.Server(
options.host || defaultOptions.host,
options.port || defaultOptions.port,
{
auto_reconnect: options.auto_reconnect ||
defaultOptions.auto_reconnect
}));
-
+ }
this.db_collection_name = options.collection || defaultOptions.collection;
if (options.hasOwnProperty('stringify') ?
@@ -260,4 +261,4 @@ module.exports = function(connect) {
};
return MongoStore;
-};
+};

0 comments on commit 36231c8

Please sign in to comment.