isage / lua-resty-moongoo

MongoDB library for OpenResty
Do What The F*ck You Want To Public License
118 stars 33 forks source link

index_information() function just returns default index "_id" info #14

Closed Filgs closed 6 years ago

Filgs commented 6 years ago

I just found a small issue in function index_information(). The current implementation is just returning the very first default index "_id" info, and it is not possible to get extra info from other indexes added by function ensure_index().

According to MongoDB documentation of function db.collection.getIndexes(), it should return an array of indexes from the selected collection. Additionally the function listIndexes() also returns a cursor with all indexes information.

Once the implementation of function index_information() is based on listIndexes() function, the solution is very simple, I just changed the file collection.lua at function _M.index_information(self) as shown below:

from: return doc.cursor.firstBatch [1] -- just return the default index "_id"

to: return doc.cursor.firstBatch -- returns all available indexes info array

Now it works just fine !

@Epifanov Ivan, Please review and update the file collection.lua as needed. Thanks a lot for your really great work!