Skip to content

Commit f12c96c

Browse files
authored
MONGOSH-273 Cursor.maxAwaitTimeMS (#326)
1 parent 601db82 commit f12c96c

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

packages/i18n/src/locales/en_US.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,10 @@ const translations = {
686686
description: 'Specifies a cumulative time limit in milliseconds for processing operations on a cursor.',
687687
example: 'db.collection.find(query, projection).maxTimeMS(timeLimit)'
688688
},
689+
maxAwaitTimeMS: {
690+
description: 'Set a maxAwaitTimeMS on a tailing cursor query to allow to customize the timeout value for the option awaitData (Only supported on MongoDB 3.2 or higher, ignored otherwise)',
691+
example: 'db.collection.find(query, projection).maxAwaitTimeMS(timeLimit)'
692+
},
689693
min: {
690694
link: 'https://docs.mongodb.com/manual/reference/method/cursor.min',
691695
description: 'Specifies the inclusive lower bound for a specific index in order to constrain the results of find(). min() provides a way to specify lower bounds on compound key indexes.',

packages/service-provider-core/src/cursor.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ export default interface ServiceProviderCursor {
171171
*/
172172
maxTimeMS(value: number): ServiceProviderCursor;
173173

174+
/**
175+
* Set the maxAwaitTimeMS value.
176+
*
177+
* @param {number} The maxAwaitTimeMS value.
178+
*
179+
* @returns {ServiceProviderCursor} The cursor.
180+
*/
181+
maxAwaitTimeMS(value: number): ServiceProviderCursor;
182+
174183
/**
175184
* Set the min index bounds.
176185
*

packages/shell-api/src/cursor.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,26 @@ describe('Cursor', () => {
347347
});
348348
});
349349

350+
describe('#maxAwaitTimeMS', () => {
351+
let spCursor: SinonStubbedInstance<ServiceProviderCursor>;
352+
let shellApiCursor;
353+
let mock;
354+
const value = 5000;
355+
356+
beforeEach(() => {
357+
mock = sinon.mock().withArgs(value);
358+
spCursor = sinon.createStubInstance(ServiceProviderCursor, {
359+
maxAwaitTimeMS: mock
360+
});
361+
shellApiCursor = new Cursor(mongo, spCursor);
362+
});
363+
364+
it('fluidly sets maxAwaitTimeMS', () => {
365+
expect(shellApiCursor.maxAwaitTimeMS(value)).to.equal(shellApiCursor);
366+
mock.verify();
367+
});
368+
});
369+
350370
describe('#min', () => {
351371
let spCursor: SinonStubbedInstance<ServiceProviderCursor>;
352372
let shellApiCursor;

packages/shell-api/src/cursor.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ export default class Cursor extends ShellApiClass {
207207
return this;
208208
}
209209

210+
@returnType('Cursor')
211+
@serverVersions(['3.2.0', ServerVersions.latest])
212+
maxAwaitTimeMS(value: number): Cursor {
213+
this._cursor.maxAwaitTimeMS(value);
214+
return this;
215+
}
216+
210217
@returnType('Cursor')
211218
min(indexBounds: Document): Cursor {
212219
this._cursor.min(indexBounds);

0 commit comments

Comments
 (0)