Closed jicvi closed 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()
So that the returned is correct:
col:find({}):limit(10):skip(0):all()
find() returns cursor, this is stated in documentation.
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 }