Error on find with Mongo (Coronium LS)

I seem to get different results for find and find_one

local myguards, error = db.User:find_one( { UserType = ‘Guard’ } )  

works great returns the first user

local myguards, error = db.User:find( { UserType = ‘Guard’ } )  

returns an error {“error”:99,“result”:“Cannot serialise userdata: type not supported”}

I believe you need to use get_pairs() with on the return object with :find

I seem to get different results for find and find_one

local myguards, error = db.User:find_one( { UserType = ‘Guard’ } )  

works great returns the first user

local myguards, error = db.User:find( { UserType = ‘Guard’ } )  

returns an error {“error”:99,“result”:“Cannot serialise userdata: type not supported”}

“find_one” returns an object while “find” returns a cursor.  

http://docs.coronium.cloud/en/latest/API/Server/MongoDB/

Sorry I should have been clearer, yes I get that it returns a cursor and I am using** return myguards:get_pairs()** and it produces that error above.

I’ve exhausted of all the ways to get find to work,

but pager seems to work to what I need…

local myguards, error = db.User:pager( { UserType = ‘Guard’ } ) … This returns a table with all the correct results

Would still like to find out what I’m doing wrong on find though.

If you’re returning the value straight from an api endpoint (which it looks like you are, error 99 is set by the output handler), cjson is likely choking on the objectID and timestamp from mongo. Pager runs the result through the parseDoc function, while find does not.

Try iterating your table and strip out the _id+_ts fields before returning it.

Pushed an update. Try it out if you could.

https://gitlab.com/coroniumcloud/Coronium-LS-CloudLib/commit/b8fe3cba02e924f010490a5dcf4da3098bce3a59

Yes when I looked at the source code for pager and get_pairs they basically do a find command but the pager parses the docs where as get_paisr doesn’t, I figured that either it was intentional or needed fixing, I didn’t have any more time this morning, but by the looks like you fixed it.

I believe you need to use get_pairs() with on the return object with :find

I seem to get different results for find and find_one

local myguards, error = db.User:find_one( { UserType = ‘Guard’ } )  

works great returns the first user

local myguards, error = db.User:find( { UserType = ‘Guard’ } )  

returns an error {“error”:99,“result”:“Cannot serialise userdata: type not supported”}

“find_one” returns an object while “find” returns a cursor.  

http://docs.coronium.cloud/en/latest/API/Server/MongoDB/

Sorry I should have been clearer, yes I get that it returns a cursor and I am using** return myguards:get_pairs()** and it produces that error above.

I’ve exhausted of all the ways to get find to work,

but pager seems to work to what I need…

local myguards, error = db.User:pager( { UserType = ‘Guard’ } ) … This returns a table with all the correct results

Would still like to find out what I’m doing wrong on find though.

If you’re returning the value straight from an api endpoint (which it looks like you are, error 99 is set by the output handler), cjson is likely choking on the objectID and timestamp from mongo. Pager runs the result through the parseDoc function, while find does not.

Try iterating your table and strip out the _id+_ts fields before returning it.

Pushed an update. Try it out if you could.

https://gitlab.com/coroniumcloud/Coronium-LS-CloudLib/commit/b8fe3cba02e924f010490a5dcf4da3098bce3a59

Yes when I looked at the source code for pager and get_pairs they basically do a find command but the pager parses the docs where as get_paisr doesn’t, I figured that either it was intentional or needed fixing, I didn’t have any more time this morning, but by the looks like you fixed it.