# Lua-resty-mongol - table insertion

**URL:** <https://www.ruby-forum.com/t/lua-resty-mongol-table-insertion/219933>\
**Category:** NGINX\
**Created:** [May 22, 2012, 1:00pm UTC](https://www.ruby-forum.com/t/lua-resty-mongol-table-insertion/219933 "2012-05-22T13:00:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [May 22, 2012, 1:00pm UTC](https://www.ruby-forum.com/t/lua-resty-mongol-table-insertion/219933/1 "2012-05-22T13:00:07Z")

</div>

Hi list,

I’m currently moving into lua-resty-mongol, and I’m facing this issue:

local versions = {}  
local t = {}  
table.insert(t,{a = “aa”})  
table.insert(t,{b = “bb”})  
versions={{name=“dog”,container=“mycontainer”,tab= t}}

mongos\> db.files.find({container:‘mycontainer’}).pretty()  
{  
“\_id” : ObjectId(“4fbb710018b42f60c829ae87”),  
“container” : “mycontainer”,  
“tab” : [  
undefined,  
{  
“a” : “aa”  
},  
{  
“b” : “bb”  
}  
],  
“name” : “dog”  
}

Why is ther “undefined” field ?

Also, pushing new info to “tab” results in resetting “tab” into new  
array of:  
[  
undefined,  
{  
“c” : “cc”  
}  
]

Did I do anything wrong or is this a bug ?

Pierre

---

<div class="post-metadata">

**Author:** ![pierre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d07c76/32.png) [@pierre](https://www.ruby-forum.com/u/pierre)\
**Post date:** [May 22, 2012, 2:56pm UTC](https://www.ruby-forum.com/t/lua-resty-mongol-table-insertion/219933/2 "2012-05-22T14:56:45Z")

</div>

to be more precise, issue can be only

reproduced when trying to  
insert table of tables

On Tue, 22 May 2012 12:59:29 +0200, Pierre  
wrote:

> Hi list,
> 
> I’m currently moving into lua-resty-mongol, and  
> I’m facing this issue:
> 
> local versions = {}  
> local t = {}

table.insert(t,{a = “aa”})

> table.insert(t,{b = “bb”})

versions={{name=“dog”,container=“mycontainer”,tab= t}}

> mongos\>  
> db.files.find({container:‘mycontainer’}).pretty()  
> {  
> “\_id” :  
> ObjectId(“4fbb710018b42f60c829ae87”),  
> “container” : “mycontainer”,

“tab” : [

> undefined,  
> {  
> “a” : “aa”  
> },  
> {  
> “b” : “bb”  
> }  
> ],

“name” : “dog”

> }
> 
> Why is ther “undefined” field ?
> 
> Also,  
> pushing new info to “tab” results in resetting “tab” into new array  
> of:  
> [  
> undefined,  
> {  
> “c” : “cc”  
> }  
> ]
> 
> Did I do anything  
> wrong or is this a bug ?
> 
> Pierre

* * *

> nginx mailing list

[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) [1]

> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)  
> [2]

Links:

---

<div class="post-metadata">

**Author:** ![pierre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d07c76/32.png) [@pierre](https://www.ruby-forum.com/u/pierre)\
**Post date:** [May 23, 2012, 8:23am UTC](https://www.ruby-forum.com/t/lua-resty-mongol-table-insertion/219933/3 "2012-05-23T08:23:09Z")

</div>

I found this problem before, but I’m not sure how to modify it. The  
reason is:

Lua table index is begin from 1, but array in mongodb is 0. So there  
will be a  
undefined element in mongodb array whose index is 0.

If we modify the driver to make index=index-1 when insert into mongodb  
and  
index=index+1 when read from mongodb, the “undefined” will be  
eliminated.  
We will found that the tab[1]=aa inserted into mongodb will be tab[0]=aa  
actual  
stored in mongodb, and it’s conflict with other language drivers.

Posted at Nginx Forum:

> **[Re: lua-resty-mongol - table insertion](https://forum.nginx.org/read.php?2,226716,226744#msg-226744)**
>
> Hi list, I'm currently moving into lua-resty-mongol, and I'm facing this issue: local versions = {} local t = {} table.insert(t,{a = "aa"}) table.insert(t,{b = "bb"}) versions={{name="dog",container="mycontainer&quo
