bigplum / lua-resty-mongol

A ngx_lua driver for mongodb -- Deprecated for not updating with the mongodb version
198 stars 67 forks source link

How can i get an object in array ? #43

Closed kakakikikeke closed 8 years ago

kakakikikeke commented 8 years ago

Hi,

I want to get the below object.

{
        "_id" : "hoge",
         "sInfo" : [
                {
                        "sToken" : "testToken",
                        "sTokenExpirationDate" : ISODate("2015-12-15T02:01:06.802Z")
                }
        ]
}

So, i built a query to get sInfo.sToken. The query is :

local query = {
   sInfo = {
      {
         sToken = "testToken"
      }
   }
}
local r = col:find_one(query)
ngx.log(ngx.ERR, r["_id"])

But, the variable of 'r' is nil. How can i get 'sInfo.sToken' ?

kakakikikeke commented 8 years ago

Sorry, i just resolved it immediately after i asked you. This is my answer.

local query = {}
local key = "sInfo.sToken"
query[key] = "testToken"
local r = col:find_one(query)

This issus is closed. Thanks.