@@ -46,14 +46,15 @@ type ChangeStream struct {
46
46
// make a copy of it.
47
47
Current bson.Raw
48
48
49
- cmd bsonx.Doc // aggregate command to run to create stream and rebuild cursor
50
- pipeline bsonx.Arr
51
- options * options.ChangeStreamOptions
52
- coll * Collection
53
- db * Database
54
- ns command.Namespace
55
- cursor * Cursor
56
- cursorOpts bsonx.Doc
49
+ cmd bsonx.Doc // aggregate command to run to create stream and rebuild cursor
50
+ pipeline bsonx.Arr
51
+ options * options.ChangeStreamOptions
52
+ coll * Collection
53
+ db * Database
54
+ ns command.Namespace
55
+ cursor * Cursor
56
+ cursorOpts bsonx.Doc
57
+ getMoreOpts bsonx.Doc
57
58
58
59
resumeToken bsonx.Doc
59
60
err error
@@ -88,11 +89,12 @@ func (cs *ChangeStream) replaceOptions(desc description.SelectedServer) {
88
89
89
90
// Create options docs for the pipeline and cursor
90
91
func createCmdDocs (csType StreamType , opts * options.ChangeStreamOptions , registry * bsoncodec.Registry ) (bsonx.Doc ,
91
- bsonx.Doc , bsonx.Doc , error ) {
92
+ bsonx.Doc , bsonx.Doc , bsonx. Doc , error ) {
92
93
93
94
pipelineDoc := bsonx.Doc {}
94
95
cursorDoc := bsonx.Doc {}
95
96
optsDoc := bsonx.Doc {}
97
+ getMoreOptsDoc := bsonx.Doc {}
96
98
97
99
if csType == ClientStream {
98
100
pipelineDoc = pipelineDoc .Append ("allChangesForCluster" , bsonx .Boolean (true ))
@@ -109,12 +111,12 @@ func createCmdDocs(csType StreamType, opts *options.ChangeStreamOptions, registr
109
111
}
110
112
if opts .MaxAwaitTime != nil {
111
113
ms := int64 (time .Duration (* opts .MaxAwaitTime ) / time .Millisecond )
112
- pipelineDoc = pipelineDoc .Append ("maxAwaitTimeMS " , bsonx .Int64 (ms ))
114
+ getMoreOptsDoc = getMoreOptsDoc .Append ("maxTimeMS " , bsonx .Int64 (ms ))
113
115
}
114
116
if opts .ResumeAfter != nil {
115
117
rt , err := transformDocument (registry , opts .ResumeAfter )
116
118
if err != nil {
117
- return nil , nil , nil , err
119
+ return nil , nil , nil , nil , err
118
120
}
119
121
120
122
pipelineDoc = pipelineDoc .Append ("resumeAfter" , bsonx .Document (rt ))
@@ -124,7 +126,7 @@ func createCmdDocs(csType StreamType, opts *options.ChangeStreamOptions, registr
124
126
bsonx .Timestamp (opts .StartAtOperationTime .T , opts .StartAtOperationTime .I ))
125
127
}
126
128
127
- return pipelineDoc , cursorDoc , optsDoc , nil
129
+ return pipelineDoc , cursorDoc , optsDoc , getMoreOptsDoc , nil
128
130
}
129
131
130
132
func getSession (ctx context.Context , client * Client ) (Session , error ) {
@@ -154,18 +156,18 @@ func getSession(ctx context.Context, client *Client) (Session, error) {
154
156
}
155
157
156
158
func parseOptions (csType StreamType , opts * options.ChangeStreamOptions , registry * bsoncodec.Registry ) (bsonx.Doc ,
157
- bsonx.Doc , bsonx.Doc , error ) {
159
+ bsonx.Doc , bsonx.Doc , bsonx. Doc , error ) {
158
160
159
161
if opts .FullDocument == nil {
160
162
opts = opts .SetFullDocument (options .Default )
161
163
}
162
164
163
- pipelineDoc , cursorDoc , optsDoc , err := createCmdDocs (csType , opts , registry )
165
+ pipelineDoc , cursorDoc , optsDoc , getMoreOptsDoc , err := createCmdDocs (csType , opts , registry )
164
166
if err != nil {
165
- return nil , nil , nil , err
167
+ return nil , nil , nil , nil , err
166
168
}
167
169
168
- return pipelineDoc , cursorDoc , optsDoc , nil
170
+ return pipelineDoc , cursorDoc , optsDoc , getMoreOptsDoc , nil
169
171
}
170
172
171
173
func (cs * ChangeStream ) runCommand (ctx context.Context , replaceOptions bool ) error {
@@ -183,7 +185,7 @@ func (cs *ChangeStream) runCommand(ctx context.Context, replaceOptions bool) err
183
185
184
186
if replaceOptions {
185
187
cs .replaceOptions (desc )
186
- optionsDoc , _ , _ , err := createCmdDocs (cs .streamType , cs .options , cs .registry )
188
+ optionsDoc , _ , _ , _ , err := createCmdDocs (cs .streamType , cs .options , cs .registry )
187
189
if err != nil {
188
190
return err
189
191
}
@@ -210,7 +212,7 @@ func (cs *ChangeStream) runCommand(ctx context.Context, replaceOptions bool) err
210
212
return err
211
213
}
212
214
213
- batchCursor , err := driver .NewBatchCursor (bsoncore .Document (rdr ), readCmd .Session , readCmd .Clock , ss .Server )
215
+ batchCursor , err := driver .NewBatchCursor (bsoncore .Document (rdr ), readCmd .Session , readCmd .Clock , ss .Server , cs . getMoreOpts ... )
214
216
if err != nil {
215
217
cs .sess .EndSession (ctx )
216
218
return err
@@ -241,7 +243,7 @@ func newChangeStream(ctx context.Context, coll *Collection, pipeline interface{}
241
243
}
242
244
243
245
csOpts := options .MergeChangeStreamOptions (opts ... )
244
- pipelineDoc , cursorDoc , optsDoc , err := parseOptions (CollectionStream , csOpts , coll .registry )
246
+ pipelineDoc , cursorDoc , optsDoc , getMoreDoc , err := parseOptions (CollectionStream , csOpts , coll .registry )
245
247
if err != nil {
246
248
return nil , err
247
249
}
@@ -275,6 +277,7 @@ func newChangeStream(ctx context.Context, coll *Collection, pipeline interface{}
275
277
options : csOpts ,
276
278
registry : coll .registry ,
277
279
cursorOpts : cursorDoc ,
280
+ getMoreOpts : getMoreDoc ,
278
281
}
279
282
280
283
err = cs .runCommand (ctx , false )
@@ -294,7 +297,7 @@ func newDbChangeStream(ctx context.Context, db *Database, pipeline interface{},
294
297
}
295
298
296
299
csOpts := options .MergeChangeStreamOptions (opts ... )
297
- pipelineDoc , cursorDoc , optsDoc , err := parseOptions (DatabaseStream , csOpts , db .registry )
300
+ pipelineDoc , cursorDoc , optsDoc , getMoreDoc , err := parseOptions (DatabaseStream , csOpts , db .registry )
298
301
if err != nil {
299
302
return nil , err
300
303
}
@@ -327,6 +330,7 @@ func newDbChangeStream(ctx context.Context, db *Database, pipeline interface{},
327
330
options : csOpts ,
328
331
registry : db .registry ,
329
332
cursorOpts : cursorDoc ,
333
+ getMoreOpts : getMoreDoc ,
330
334
}
331
335
332
336
err = cs .runCommand (ctx , false )
@@ -346,7 +350,7 @@ func newClientChangeStream(ctx context.Context, client *Client, pipeline interfa
346
350
}
347
351
348
352
csOpts := options .MergeChangeStreamOptions (opts ... )
349
- pipelineDoc , cursorDoc , optsDoc , err := parseOptions (ClientStream , csOpts , client .registry )
353
+ pipelineDoc , cursorDoc , optsDoc , getMoreDoc , err := parseOptions (ClientStream , csOpts , client .registry )
350
354
if err != nil {
351
355
return nil , err
352
356
}
@@ -379,6 +383,7 @@ func newClientChangeStream(ctx context.Context, client *Client, pipeline interfa
379
383
options : csOpts ,
380
384
registry : client .registry ,
381
385
cursorOpts : cursorDoc ,
386
+ getMoreOpts : getMoreDoc ,
382
387
}
383
388
384
389
err = cs .runCommand (ctx , false )
0 commit comments