Skip to content

Commit

Permalink
default key ascending
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwu committed Jun 13, 2016
1 parent bd3d9b7 commit fd2c814
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lualib/mongo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,13 @@ local function IndexModel(option)
local keys = {}
local name
for _, kv in ipairs(option) do
local k,v = next(kv)
local k,v
if type(kv) == "string" then
k = kv
v = 1
else
k,v = next(kv)
end
table.insert(keys, k)
table.insert(keys, v)
name = (name == nil) and k or (name .. "_" .. k)
Expand All @@ -358,6 +364,8 @@ local function IndexModel(option)
end

-- collection:createIndex { { key1 = 1}, { key2 = 1 }, unique = true }
-- or collection:createIndex { "key1", "key2", unique = true }
-- or collection:createIndex( { key1 = 1} , { unique = true } ) -- For compatibility
function mongo_collection:createIndex(arg1 , arg2)
if arg2 then
return createIndex_onekey(self, arg1, arg2)
Expand Down

0 comments on commit fd2c814

Please sign in to comment.