bigplum / lua-resty-mongol

A ngx_lua driver for mongodb -- Deprecated for not updating with the mongodb version
198 stars 67 forks source link

How to delete collection by id #73

Closed DreamerLiJinwen closed 4 years ago

DreamerLiJinwen commented 4 years ago

" col:delete({_id = "5ef858a7dca5d3bde95467fc"}, 1, 0) " , delete fail

DreamerLiJinwen commented 4 years ago

solution

function convertHexStringToNormal(str)
    return (str:gsub(
        "..",
        function(cc)
            return string.char(tonumber(cc, 16))
        end
    ))
end

col:delete({_id = object_id.new(convertHexStringToNormal(id))}, 1, 0)