lua-resty-mongol
lua-resty-mongol copied to clipboard
Dealing onlyarray in 'to_bson' function may cause data loss
As we know, when we iterate table with pairs in lua, it doesn't guarantee the order as we defines in table. http://www.lua.org/manual/5.2/manual.html#pdf-next
if onlyarray then
if t_k == "number" and k >= 0 then
if k >= high_n then
high_n = k
seen_n [ k ] = v
end
else
onlyarray = false
end
end
the code above deals array in to_bson in bson.lua, array value will store in seen_n only if k >= high_n, however this condition won't always be true. It means we may lost some value and results in 'null' stores in mongodb. I think seen_n [ k ] = v should be moved out of the if condition and we can hold all the data.
https://github.com/aaashun/lua-resty-mongol/issues/5 closed