Skip to content

Commit 6c69b7d

Browse files
authored
fix(NODE-4467): Add back support for oplogReplay option as deprecated (#3337)
1 parent 7e462c9 commit 6c69b7d

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

src/operations/find.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ export interface FindOptions<TSchema extends Document = Document> extends Comman
6363
showRecordId?: boolean;
6464
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
6565
let?: Document;
66+
/**
67+
* Option to enable an optimized code path for queries looking for a particular range of `ts` values in the oplog. Requires `tailable` to be true.
68+
* @deprecated Starting from MongoDB 4.4 this flag is not needed and will be ignored.
69+
*/
70+
oplogReplay?: boolean;
6671
}
6772

6873
const SUPPORTS_WRITE_CONCERN_AND_COLLATION = 5;
@@ -242,6 +247,10 @@ function makeFindCommand(ns: MongoDBNamespace, filter: Document, options: FindOp
242247
findCommand.tailable = options.tailable;
243248
}
244249

250+
if (typeof options.oplogReplay === 'boolean') {
251+
findCommand.oplogReplay = options.oplogReplay;
252+
}
253+
245254
if (typeof options.timeout === 'boolean') {
246255
findCommand.noCursorTimeout = !options.timeout;
247256
} else if (typeof options.noCursorTimeout === 'boolean') {

test/unit/operations/find.test.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { expect } from 'chai';
2+
import * as sinon from 'sinon';
3+
import { promisify } from 'util';
4+
5+
import { FindOperation } from '../../../src/operations/find';
6+
import { Server } from '../../../src/sdam/server';
7+
import { ServerDescription } from '../../../src/sdam/server_description';
8+
import { Topology } from '../../../src/sdam/topology';
9+
import { ns } from '../../../src/utils';
10+
11+
describe('FindOperation', function () {
12+
const namespace = ns('db.coll');
13+
const options = {
14+
batchSize: 100
15+
};
16+
const filter = {
17+
ts: { $gt: new Date() }
18+
};
19+
20+
afterEach(function () {
21+
sinon.restore();
22+
});
23+
24+
describe('#constructor', function () {
25+
const operation = new FindOperation(undefined, namespace, filter, options);
26+
27+
it('sets the namespace', function () {
28+
expect(operation.ns).to.equal(namespace);
29+
});
30+
31+
it('sets options', function () {
32+
expect(operation.options).to.equal(options);
33+
});
34+
35+
it('sets filter', function () {
36+
expect(operation.filter).to.equal(filter);
37+
});
38+
});
39+
40+
describe('#execute', function () {
41+
context('command construction', () => {
42+
const namespace = ns('db.collection');
43+
const server = new Server(new Topology([], {} as any), new ServerDescription(''), {} as any);
44+
45+
it('should build basic find command with filter', async () => {
46+
const findOperation = new FindOperation(undefined, namespace, filter);
47+
const stub = sinon.stub(server, 'command').yieldsRight();
48+
await promisify(findOperation.execute.bind(findOperation))(server, undefined);
49+
expect(stub).to.have.been.calledOnceWith(namespace, {
50+
find: namespace.collection,
51+
filter
52+
});
53+
});
54+
55+
it('should build find command with oplogReplay', async () => {
56+
const options = {
57+
oplogReplay: true
58+
};
59+
const findOperation = new FindOperation(undefined, namespace, {}, options);
60+
const stub = sinon.stub(server, 'command').yieldsRight();
61+
await promisify(findOperation.execute.bind(findOperation))(server, undefined);
62+
expect(stub).to.have.been.calledOnceWith(
63+
namespace,
64+
sinon.match.has('oplogReplay', options.oplogReplay)
65+
);
66+
});
67+
});
68+
});
69+
});

0 commit comments

Comments
 (0)