Skip to content

Commit 536d2e9

Browse files
author
johnxu
committed
- allow null in document as bson_null
1 parent 682ad31 commit 536d2e9

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/resty/mongol/bson.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ local new_object_id = obid.new
2727
local object_id_mt = obid.metatable
2828
local binary_mt = {}
2929
local utc_date = {}
30+
local bson_null = {}
3031

3132

3233
local function read_document ( get , numerical )
@@ -68,7 +69,7 @@ local function read_document ( get , numerical )
6869
elseif op == "\9" then -- UTC datetime milliseconds
6970
v = le_uint_to_num ( get ( 8 ) , 1 , 8 )
7071
elseif op == "\10" then -- Null
71-
v = nil
72+
v = bson_null
7273
elseif op == "\16" then --int32
7374
v = le_int_to_num ( get ( 4 ) , 1 , 8 )
7475
elseif op == "\17" then --int64
@@ -209,8 +210,9 @@ function to_bson(ob)
209210
end
210211

211212
return {
212-
from_bson = from_bson ;
213-
to_bson = to_bson ;
213+
from_bson = from_bson;
214+
to_bson = to_bson;
215+
bson_null = bson_null;
214216
get_bin_data = get_bin_data;
215217
get_utc_date = get_utc_date;
216218
}

lib/resty/mongol/init.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ local connmethods = { }
1212
local connmt = { __index = connmethods }
1313

1414
local dbmt = require ( mod_name .. ".dbmt" )
15+
local bson = require ( mod_name .. ".bson" )
16+
null = bson.bson_null
1517

1618
function connmethods:ismaster()
1719
local db = self:new_db_handle("admin")

0 commit comments

Comments
 (0)