@@ -3,8 +3,6 @@ defmodule Mongo.ChangeStream do
3
3
alias Mongo.Session
4
4
alias Mongo.Error
5
5
6
- require Logger
7
-
8
6
import Record , only: [ defrecordp: 2 ]
9
7
10
8
defstruct [ :topology_pid , :session , :doc , :cmd , :on_resume_token , :opts ]
@@ -71,7 +69,6 @@ defmodule Mongo.ChangeStream do
71
69
72
70
def aggregate ( topology_pid , cmd , fun , opts ) do
73
71
74
- Logger . info ( "start_implicit_session " )
75
72
with { :ok , session } <- Session . start_implicit_session ( topology_pid , :read , opts ) ,
76
73
{ :ok , % { "ok" => ok } = doc } when ok == 1 <- Mongo . exec_command_session ( session , cmd , opts ) do
77
74
@@ -87,13 +84,11 @@ defmodule Mongo.ChangeStream do
87
84
88
85
def aggregate ( topology_pid , session , doc , cmd , fun ) do
89
86
90
- Logger . info ( "aggregate wire version: #{ inspect Mongo . wire_version ( topology_pid ) } " )
91
87
with % { "operationTime" => op_time ,
92
88
"cursor" => % {
93
89
"id" => cursor_id ,
94
90
"ns" => coll ,
95
- "firstBatch" => docs } = response } <- doc ,
96
- { :ok , wire_version } <- Mongo . wire_version ( topology_pid ) do
91
+ "firstBatch" => docs } = response } <- doc do
97
92
98
93
[ % { "$changeStream" => stream_opts } | _pipeline ] = Keyword . get ( cmd , :pipeline ) # extract the change stream options
99
94
@@ -105,7 +100,7 @@ defmodule Mongo.ChangeStream do
105
100
# The initial aggregate response did not include a postBatchResumeToken.
106
101
107
102
has_values = stream_opts [ "startAtOperationTime" ] || stream_opts [ "startAfter" ] || stream_opts [ "resumeAfter" ]
108
- op_time = update_operation_time ( op_time , has_values , docs , response [ "postBatchResumeToken" ] , wire_version )
103
+ op_time = update_operation_time ( op_time , has_values , docs , response [ "postBatchResumeToken" ] , Session . wire_version ( session ) )
109
104
110
105
# When the ChangeStream is started:
111
106
# If startAfter is set, cache it.
@@ -132,7 +127,6 @@ defmodule Mongo.ChangeStream do
132
127
change_stream ( resume_token: resume_token , op_time: op_time , cmd: aggregate_cmd ,
133
128
on_resume_token: fun ) = change_stream , opts ) do
134
129
135
- Logger . info ( "Get more" )
136
130
get_more = [
137
131
getMore: % BSON.LongNumber { value: cursor_id } ,
138
132
collection: coll ,
@@ -159,26 +153,20 @@ defmodule Mongo.ChangeStream do
159
153
{ :error , % Mongo.Error { resumable: false } = not_resumable } -> { :error , not_resumable }
160
154
{ :error , _error } ->
161
155
162
- Logger . info ( "Resuming....: #{ inspect Mongo . wire_version ( topology_pid ) } " )
163
- with { :ok , wire_version } <- Mongo . wire_version ( topology_pid ) do
164
-
165
- [ % { "$changeStream" => stream_opts } | pipeline ] = Keyword . get ( aggregate_cmd , :pipeline ) # extract the change stream options
156
+ [ % { "$changeStream" => stream_opts } | pipeline ] = Keyword . get ( aggregate_cmd , :pipeline ) # extract the change stream options
166
157
167
- stream_opts = update_stream_options ( stream_opts , resume_token , op_time , wire_version )
168
- aggregate_cmd = Keyword . update! ( aggregate_cmd , :pipeline , fn _ -> [ % { "$changeStream" => stream_opts } | pipeline ] end )
158
+ stream_opts = update_stream_options ( stream_opts , resume_token , op_time , Session . wire_version ( session ) )
159
+ aggregate_cmd = Keyword . update! ( aggregate_cmd , :pipeline , fn _ -> [ % { "$changeStream" => stream_opts } | pipeline ] end )
169
160
170
- # kill the cursor
171
- kill_cursors ( session , coll , [ cursor_id ] , opts )
161
+ # kill the cursor
162
+ kill_cursors ( session , coll , [ cursor_id ] , opts )
172
163
173
- # Start aggregation again...
174
- Logger . info ( "Calling aggregate again" )
175
- with { :ok , state } <- aggregate ( topology_pid , aggregate_cmd , fun , opts ) do
176
- { :resume , state }
177
- end
164
+ # Start aggregation again...
165
+ with { :ok , state } <- aggregate ( topology_pid , aggregate_cmd , fun , opts ) do
166
+ { :resume , state }
178
167
end
179
168
reason ->
180
- Logger . info ( "Error: #{ inspect reason } " )
181
- { :error , nil }
169
+ { :error , reason }
182
170
end
183
171
end
184
172
@@ -260,7 +248,6 @@ defmodule Mongo.ChangeStream do
260
248
"""
261
249
def kill_cursors ( session , coll , cursor_ids , opts ) do
262
250
263
- ## todo Logger.info("Kill-Cursor")
264
251
cmd = [
265
252
killCursors: coll ,
266
253
cursors: cursor_ids |> Enum . map ( fn id -> % BSON.LongNumber { value: id } end )
0 commit comments