Skip to content

Commit ce0e32f

Browse files
authored
Merge pull request #251 from Larrouse2015/master
cursor bug fix
2 parents 7f9deef + 94b1cfc commit ce0e32f

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

include/mongo_protocol.hrl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
-record(getmore, {
4949
collection :: colldb(),
5050
batchsize = 0 :: mc_worker_api:batchsize(),
51-
cursorid :: mc_worker_api:cursorid()
51+
cursorid :: mc_worker_api:cursorid(),
52+
database :: database()
5253
}).
5354

5455
%% system

src/connection/mc_connection_man.erl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
read(Connection, Request) -> read(Connection, Request, undefined).
2525

2626
-spec read(pid() | atom(), query(), undefined | mc_worker_api:batchsize()) -> [] | {ok, pid()}.
27-
read(Connection, Request = #'query'{collection = Collection, batchsize = BatchSize}, CmdBatchSize) ->
27+
read(Connection, Request = #'query'{collection = Collection, batchsize = BatchSize, database = DB}, CmdBatchSize) ->
2828
case request_worker(Connection, Request) of
2929
{_, []} ->
3030
[];
3131
{Cursor, Batch} ->
32-
mc_cursor:start_link(Connection, Collection, Cursor, select_batchsize(CmdBatchSize, BatchSize), Batch)
32+
mc_cursor:start_link(Connection, Collection, Cursor, select_batchsize(CmdBatchSize, BatchSize), Batch, DB)
3333
end.
34+
3435

3536
-spec read_one(pid() | atom(), query()) -> undefined | map().
3637
read_one(Connection, Request) ->

src/connection/mc_cursor.erl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
]).
1616

1717
-export([
18-
start_link/5
18+
start_link/5,
19+
start_link/6
1920
]).
2021

22+
2123
-export([
2224
init/1,
2325
handle_call/3,
@@ -33,7 +35,8 @@
3335
cursor :: integer(),
3436
batchsize :: integer(),
3537
batch :: [bson:document()],
36-
monitor :: reference()
38+
monitor :: reference(),
39+
database :: database()
3740
}).
3841

3942

@@ -111,19 +114,22 @@ close(Cursor) ->
111114
gen_server:cast(Cursor, halt).
112115

113116
start_link(Connection, Collection, Cursor, BatchSize, Batch) ->
114-
gen_server:start_link(?MODULE, [self(), Connection, Collection, Cursor, BatchSize, Batch], []).
117+
gen_server:start_link(?MODULE, [self(), Connection, Collection, Cursor, BatchSize, Batch,undefined], []).
118+
start_link(Connection, Collection, Cursor, BatchSize, Batch, DB) ->
119+
gen_server:start_link(?MODULE, [self(), Connection, Collection, Cursor, BatchSize, Batch,DB], []).
115120

116121

117122
%% @hidden
118-
init([Owner, Connection, Collection, Cursor, BatchSize, Batch]) ->
123+
init([Owner, Connection, Collection, Cursor, BatchSize, Batch,DB]) ->
119124
Monitor = erlang:monitor(process, Owner),
120125
{ok, #state{
121126
connection = Connection,
122127
collection = Collection,
123128
cursor = Cursor,
124129
batchsize = BatchSize,
125130
batch = format_batch(Batch),
126-
monitor = Monitor
131+
monitor = Monitor,
132+
database = DB
127133
}}.
128134

129135
%% @hidden
@@ -181,7 +187,8 @@ next_i(#state{batch = []} = State, Timeout) ->
181187
#getmore{
182188
collection = State#state.collection,
183189
batchsize = State#state.batchsize,
184-
cursorid = State#state.cursor
190+
cursorid = State#state.cursor,
191+
database = State#state.database
185192
},
186193
Timeout),
187194
Cursor = Reply#reply.cursorid,

src/connection/mc_worker.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ get_set_opts_module(Options) ->
217217
end.
218218

219219
%% @private
220-
get_database(#getmore{}, ConnState) -> ConnState#conn_state.database;
220+
get_database(#getmore{database = undefined}, ConnState) -> ConnState#conn_state.database;
221221
get_database(#query{database = undefined}, ConnState) -> ConnState#conn_state.database;
222222
get_database(#ensure_index{database = undefined}, ConnState) -> ConnState#conn_state.database;
223+
get_database(#getmore{database = DB}, _) -> DB;
223224
get_database(#query{database = DB}, _) -> DB;
224225
get_database(#ensure_index{database = DB}, _) -> DB.

0 commit comments

Comments
 (0)