isage / lua-resty-moongoo

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

Count returns userdata? #13

Closed CriztianiX closed 7 years ago

CriztianiX commented 7 years ago

Why count() returns userdata instead int?

local x = mongo.get_collection("my_test_collection"):find({})
local a = x:count()
type(a)
handler(): "userdata"
isage commented 7 years ago

That's because lua-cbson (and so lua-moongoo) decodes all numbers as cbson.int/cbson.uint. You can, however, compare them to normal lua numbers (to some extent, because lua number limit is smaller than C/mongo one, because internally all numbers in lua 5.1 are floats)

On Sep 1, 2017 7:38 PM, "Cristian Haunsen" notifications@github.com wrote:

Why count() returns userdata instead int?

local x = mongo.get_collection("my_test_collection"):find({})local a = x:count()type(a)

handler(): "userdata"

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/isage/lua-resty-moongoo/issues/13, or mute the thread https://github.com/notifications/unsubscribe-auth/AAQtIZKHnKhBYsqgBp9k5ZprlFaq0cefks5seDMdgaJpZM4PKYRw .