comparison mod_storage_mongodb/mod_storage_mongodb.lua @ 507:46f578da4ff0

mod_storage_mongodb: assert the configuration options
author James Callahan <james@chatid.com>
date Wed, 14 Dec 2011 12:47:49 +1100
parents 0e07810550c8
children 9831506dcfd6
comparison
equal deleted inserted replaced
506:0e07810550c8 507:46f578da4ff0
1 local next = next; 1 local next = next;
2 local setmetatable = setmetatable; 2 local setmetatable = setmetatable;
3 3
4 local log = require "util.logger".init("mongodb"); 4 local params = assert ( module:get_option("mongodb") , "mongodb configuration not found" );
5 local params = module:get_option("mongodb");
6 5
7 local mongo = require "mongo"; 6 local mongo = require "mongo";
8 7
9 local conn = mongo.Connection.New ( true ); 8 local conn = mongo.Connection.New ( true );
10 conn:connect ( params.server ); 9 conn:connect ( params.server );
15 14
16 function keyval_store:get(username) 15 function keyval_store:get(username)
17 local host = module.host or "_global"; 16 local host = module.host or "_global";
18 local store = self.store; 17 local store = self.store;
19 18
19 -- The database name can't have a period in it (hence it can't be a host/ip)
20 local namespace = params.dbname .. "." .. host; 20 local namespace = params.dbname .. "." .. host;
21 local v = { _id = { store = store ; username = username } }; 21 local v = { _id = { store = store ; username = username } };
22 22
23 local cursor , err = conn:query ( namespace , v ); 23 local cursor , err = conn:query ( namespace , v );
24 if not cursor then return nil , err end; 24 if not cursor then return nil , err end;
30 30
31 function keyval_store:set(username, data) 31 function keyval_store:set(username, data)
32 local host = module.host or "_global"; 32 local host = module.host or "_global";
33 local store = self.store; 33 local store = self.store;
34 34
35 -- The database name can't have a period in it (hence it can't be a host/ip)
35 local namespace = params.dbname .. "." .. host; 36 local namespace = params.dbname .. "." .. host;
36 local v = { _id = { store = store ; username = username } }; 37 local v = { _id = { store = store ; username = username } };
37 38
38 if next(data) ~= nil then -- set data 39 if next(data) ~= nil then -- set data
39 v.data = data; 40 v.data = data;