@@ -4,6 +4,7 @@ import { MongoAPIError, MongoUnexpectedServerResponseError } from '../error';
4
4
import { executeOperation , ExecutionResult } from '../operations/execute_operation' ;
5
5
import { GetMoreOperation } from '../operations/get_more' ;
6
6
import { RunCommandOperation } from '../operations/run_command' ;
7
+ import type { ReadConcernLike } from '../read_concern' ;
7
8
import type { ReadPreferenceLike } from '../read_preference' ;
8
9
import type { ClientSession } from '../sessions' ;
9
10
import { Callback , ns } from '../utils' ;
@@ -30,22 +31,61 @@ export class RunCommandCursor extends AbstractCursor {
30
31
batchSize ?: number ;
31
32
} = { } ;
32
33
33
- public setComment ( comment : any ) {
34
+ /**
35
+ * Controls the `getMore.comment` field
36
+ * @param comment - any BSON value
37
+ */
38
+ public setComment ( comment : any ) : this {
34
39
this . getMoreOptions . comment = comment ;
40
+ return this ;
35
41
}
36
42
37
- public setMaxTimeMS ( maxTimeMS : number ) {
43
+ /**
44
+ * Controls the `getMore.maxTimeMS` field. Only valid when cursor is tailable await
45
+ * @param maxTimeMS - the number of milliseconds to wait for new data
46
+ */
47
+ public setMaxTimeMS ( maxTimeMS : number ) : this {
38
48
this . getMoreOptions . maxAwaitTimeMS = maxTimeMS ;
49
+ return this ;
39
50
}
40
51
41
- public setBatchSize ( batchSize : number ) {
52
+ /**
53
+ * Controls the `getMore.batchSize` field
54
+ * @param maxTimeMS - the number documents to return in the `nextBatch`
55
+ */
56
+ public setBatchSize ( batchSize : number ) : this {
42
57
this . getMoreOptions . batchSize = batchSize ;
58
+ return this ;
43
59
}
44
60
45
61
public clone ( ) : never {
46
62
throw new MongoAPIError ( 'RunCommandCursor cannot be cloned' ) ;
47
63
}
48
64
65
+ public override withReadConcern ( _ : ReadConcernLike ) : never {
66
+ throw new MongoAPIError (
67
+ 'RunCommandCursor does not support readConcern it must be attached to the command being run'
68
+ ) ;
69
+ }
70
+
71
+ public override addCursorFlag ( _ : string , __ : boolean ) : never {
72
+ throw new MongoAPIError (
73
+ 'RunCommandCursor does not support cursor flags, they must be attached to the command being run'
74
+ ) ;
75
+ }
76
+
77
+ public override maxTimeMS ( _ : number ) : never {
78
+ throw new MongoAPIError (
79
+ 'RunCommandCursor does not support maxTimeMS, it must be attached to the command being run'
80
+ ) ;
81
+ }
82
+
83
+ public override batchSize ( _ : number ) : never {
84
+ throw new MongoAPIError (
85
+ 'RunCommandCursor does not support batchSize, it must be attached to the command being run'
86
+ ) ;
87
+ }
88
+
49
89
/** @internal */
50
90
private db : Db | undefined ;
51
91
@@ -61,7 +101,7 @@ export class RunCommandCursor extends AbstractCursor {
61
101
const operation = new RunCommandOperation < RunCursorCommandResponse > ( this . db , this . command , {
62
102
...this . cursorOptions ,
63
103
session : session ,
64
- readPreference : this . readPreference
104
+ readPreference : this . cursorOptions . readPreference
65
105
} ) ;
66
106
executeOperation ( this . client , operation ) . then (
67
107
response => {
0 commit comments