Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lua-mongo.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ op_insert(lua_State *L) {
int i;
for (i=1;i<=s;i++) {
lua_rawgeti(L,3,i);
document doc = lua_touserdata(L,3);
document doc = lua_touserdata(L,-1);
lua_pop(L,1); // must call lua_pop before luaL_addlstring, because addlstring may change stack top
luaL_addlstring(&b, (const char *)doc, get_length(doc));
}
Expand Down
28 changes: 28 additions & 0 deletions mongo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,21 @@ function mongo_collection:findOne(query, selector)
return bson_decode(doc)
end

function mongo_collection:findOneSecondary(query, selector)
local request_id = self.connection:genId()
local sock = self.connection.__sock
local pack = driver.query(request_id, 4, self.full_name, 0, 1,
query and bson_encode(query) or empty_bson, selector and bson_encode(selector))

-- todo: check send
socket.write(sock, pack)

local _, _, reply_id, doc = get_reply(sock)
assert(request_id == reply_id, "Reply from mongod error")
-- todo: check succ
return bson_decode(doc)
end

function mongo_collection:find(query, selector)
return setmetatable( {
__collection = self,
Expand All @@ -207,6 +222,19 @@ function mongo_collection:find(query, selector)
} , cursor_meta)
end

function mongo_collection:findSecondary(query, selector)
return setmetatable( {
__collection = self,
__query = query and bson_encode(query) or empty_bson,
__selector = selector and bson_encode(selector),
__ptr = nil,
__data = nil,
__cursor = nil,
__document = {},
__flags = 4,
} , cursor_meta)
end

function mongo_cursor:hasNext()
if self.__ptr == nil then
if self.__document == nil then
Expand Down