isage / lua-resty-moongoo

MongoDB library for OpenResty
Do What The F*ck You Want To Public License
118 stars 33 forks source link

Excuse me ! coll:find({}) return config info ? No coll data return #39

Closed jicvi closed 4 years ago

jicvi commented 4 years ago

local doc, err = col:find({}) return : { "_limit" : 0.0, "_explain" : false, "_skip" : 0.0, "_started" : false, "_tailable" : false, "_query" : { }, "_collection" : { "name" : "col_test", "_db" : { "_moongoo" : { "hosts" : [ { "host" : "172.17.0.3", "port" : "27017" } ], "journal" : false, "ssl" : false, "user" : "root", "auth_algo" : "SCRAM-SHA-1", "w" : 1.0, "wtimeout" : 1000.0, "password" : "123456", "default_db" : "admin" }, "name" : "myTest" } }, "_cnt" : 0.0, "_docs" : { }, "_await" : false, "_id" : 0 }

jicvi commented 4 years ago

This is the code :

local moongoo = require("resty.moongoo") local cbson =require("cbson")

local con, err = moongoo.new("mongodb://root:123456@172.17.0.3:27017") if not con then error(err) end

local db=con:db("myTest")

local col = db:collection("col_test")

--local ids,err=col:insert({_id="test1", name="test1"}) --ngx.log(ngx.ERR,err) --local doc, err = col:find_one({ name = "test1"})

local doc, err = col:find({}) local bson_data = cbson.encode(doc) ngx.say("err::",err)

ngx.say("local doc, err = col:find({}) return :",cbson.to_json(bson_data))

con:close()

jicvi commented 4 years ago

So that the returned is correct:

col:find({}):limit(10):skip(0):all()

isage commented 4 years ago

find() returns cursor, this is stated in documentation.