From 536d2e941604d1b5d01c69b528697b057984bd9f Mon Sep 17 00:00:00 2001 From: johnxu Date: Thu, 26 Feb 2015 14:33:44 +0800 Subject: [PATCH 1/2] - allow null in document as bson_null --- lib/resty/mongol/bson.lua | 8 +++++--- lib/resty/mongol/init.lua | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) 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/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") From 532c10f451b2db654015fe39e99c078869098f07 Mon Sep 17 00:00:00 2001 From: boyxuper Date: Tue, 10 Mar 2015 21:28:06 +0800 Subject: [PATCH 2/2] - compatible with 3rd-party bson encoder --- lib/resty/mongol/colmt.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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