lua-resty-mongol icon indicating copy to clipboard operation
lua-resty-mongol copied to clipboard

Dealing onlyarray in 'to_bson' function may cause data loss

Open Gerrard-YNWA opened this issue 9 years ago • 1 comments

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.

Gerrard-YNWA avatar Jun 04 '16 15:06 Gerrard-YNWA

https://github.com/aaashun/lua-resty-mongol/issues/5 closed

aaashun avatar Jul 04 '16 09:07 aaashun