changeset 508:9831506dcfd6

mod_storage_mongodb: move database connecting to inside driver:open
author James Callahan <james@chatid.com>
date Wed, 14 Dec 2011 12:56:07 +1100
parents 46f578da4ff0
children bf2ad6d6c778 59e80326f2b3
files mod_storage_mongodb/mod_storage_mongodb.lua
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mod_storage_mongodb/mod_storage_mongodb.lua	Wed Dec 14 12:47:49 2011 +1100
+++ b/mod_storage_mongodb/mod_storage_mongodb.lua	Wed Dec 14 12:56:07 2011 +1100
@@ -5,9 +5,7 @@
 
 local mongo = require "mongo";
 
-local conn = mongo.Connection.New ( true );
-conn:connect ( params.server );
-conn:auth ( params );
+local conn
 
 local keyval_store = {};
 keyval_store.__index = keyval_store;
@@ -47,6 +45,12 @@
 local driver = { name = "mongodb" };
 
 function driver:open(store, typ)
+	if not conn then
+		conn = assert ( mongo.Connection.New ( true ) );
+		assert ( conn:connect ( params.server ) );
+		assert ( conn:auth ( params ) );
+	end
+
 	if not typ then -- default key-value store
 		return setmetatable({ store = store }, keyval_store);
 	end;