diff --git a/lib/resty/mongol/bson.lua b/lib/resty/mongol/bson.lua index 8abcf98..90adb71 100755 --- a/lib/resty/mongol/bson.lua +++ b/lib/resty/mongol/bson.lua @@ -27,6 +27,7 @@ local new_object_id = obid.new local object_id_mt = obid.metatable local binary_mt = {} local utc_date = {} +local bson_null = {} local function read_document ( get , numerical ) @@ -68,7 +69,7 @@ local function read_document ( get , numerical ) elseif op == "\9" then -- UTC datetime milliseconds v = le_uint_to_num ( get ( 8 ) , 1 , 8 ) elseif op == "\10" then -- Null - v = nil + v = bson_null elseif op == "\16" then --int32 v = le_int_to_num ( get ( 4 ) , 1 , 8 ) elseif op == "\17" then --int64 @@ -209,8 +210,9 @@ function to_bson(ob) end return { - from_bson = from_bson ; - to_bson = to_bson ; + from_bson = from_bson; + to_bson = to_bson; + bson_null = bson_null; get_bin_data = get_bin_data; get_utc_date = get_utc_date; } diff --git a/lib/resty/mongol/colmt.lua b/lib/resty/mongol/colmt.lua index 0777aa5..bcc985d 100755 --- a/lib/resty/mongol/colmt.lua +++ b/lib/resty/mongol/colmt.lua @@ -218,7 +218,9 @@ function colmethods:query(query, returnfields, numberToSkip, numberToReturn, opt + 2^7*( options.Partial and 1 or 0 ) end - query = to_bson(query) + if type(query) ~= "string" then + query = to_bson(query) + end if returnfields then returnfields = to_bson(returnfields) else diff --git a/lib/resty/mongol/init.lua b/lib/resty/mongol/init.lua index d6e76bd..52c88d1 100755 --- a/lib/resty/mongol/init.lua +++ b/lib/resty/mongol/init.lua @@ -12,6 +12,8 @@ local connmethods = { } local connmt = { __index = connmethods } local dbmt = require ( mod_name .. ".dbmt" ) +local bson = require ( mod_name .. ".bson" ) +null = bson.bson_null function connmethods:ismaster() local db = self:new_db_handle("admin")