Unable to properly access data tables from MongoDB - coronium:getObject( ) method

5 views
Skip to first unread message

Jonathan Sharp

unread,
Feb 7, 2016, 12:52:07 PM2/7/16
to Coronium IO
Basically, I can't access my table information properly after it returns from MongoDB via the coronium:getObject( ) method and I'm hoping there's some quick and obvious solution that has escaped me.

I started by creating an object (a table named "data") and  I'm able to access the elements of the table via the print( ) method with no problems

local data = {
name = "color",
[1] = { name = "red", value = 0},
[2] = { name = "yellow", value = 0},
[3] = { name = "blue", value = 0}
}

print( data.name )  -- outputs "color"
print( #data ) -- outputs 3
print( data[1].name ) -- outputs "red"


I then "push" the table object to MongoDB and get the objectID

mc:createObject( "soma", data, function(e) 
if not event.error then
local r = e.result.objectId 
print( r ) -- outputs "4262979782"
end
end)

       
But when I "pull" the object back to Corona and run the following code I am unable to properly access the data.

coronium:getObject( "soma", "4262979782", function(e) 
local r = e.result
print( r.name .. " from result" )  -- outputs "color"
        print( #r .. " nodes from result" ) -- *** outputs 0 
print( r[1].name .. " from result" ) -- *** Runtime error : attempt to index field '?' (a nil value) 
end)

It's probably a JSON to Lua problem, right?  Anyone have a fix for this?

Thanks,
Jonathan
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages