lua-resty-mongol
lua-resty-mongol copied to clipboard
I use mongodb 3.x,db:auth(user,pwd) can't work.Is this program need upgrade?
local mongo = require "resty.mongol" local host_info = { host="192.168.1.2", port=27017, username="ttt", password="ttt" } conn = mongo:new() conn:set_timeout(2000) ok, err = conn:connect(host_info["host"], host_info["port"]) ngx.say(ok,err) -- 1 nil if not ok then ngx.log("connect failed: "..err) end local db = conn:new_db_handle("ttt") ok, err = db:auth(host_info["username"], host_info["password"]) ngx.say(ok, err) -- nil lauth failed col = db:get_col("tt") r = col:find_one({a=1}) if r == nil then return false else ngx.say(r["_id"]) return true end
I've got the same issue here. No success in Mongo 3.x auth, got a Mongo 2.6 running and managed to connect with no problems using the same code.
You must modify the source code,because Mongo 2.6 use md5 Encrypt,Mongo 3.x use sha1 Encrypt。 modify the dbmt.lua file.
local function pass_digest ( username , password ) return ngx.md5(username .. ":mongo:" .. password) end