-2

I am using corona (lua) with parse.com and I have hit a problem constructing an $in query using values from another table / array.

My code is a little like this:

local usersToFetch = {}
table.insert( usersToFetch, "KnVvDiV2Cj")
table.insert( usersToFetch, "Paf6LDmykp")

and the working query I want to perform is the following lua table (which will get encoded before heading to parse). As I said, this works when I am hard coding the values as shown

   local queryTable = {
      ["where"] = { 
                    ["objectId"] = { ["$in"] = {"KnVvDiV2Cj","Paf6LDmykp"  }} 
                  },
      ["limit"] = 1000

    }

My problem is how do I incorporate my 'usersToFetch' table in the above table so that it will work the same as hard coding the values?

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
user3781891
  • 135
  • 10

1 Answers1

2

I swore I tried that but clearly I did not.. I think that I placed it inside the braces whereas they are not needed which is where I went wrong.

Thanks, hjpotte92 - what you put worked fine but this is my final solution in a single declaration:

Where I was going wrong before was because I had too many braces ["objectId"] = { ["$in"] = { usersToFetch } }

    local queryTable = {
      ["where"] = { 
                    ["objectId"] = { ["$in"] = usersToFetch} 
                  },
      ["limit"] = 1000

    }
user3781891
  • 135
  • 10