Skip to content

Commit

Permalink
fix(NODE-4467): Add back support for oplogReplay option as deprecat…
Browse files Browse the repository at this point in the history
…ed (#3337)
  • Loading branch information
sampaiodiego authored Aug 1, 2022
1 parent 7e462c9 commit 6c69b7d
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/operations/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ export interface FindOptions<TSchema extends Document = Document> extends Comman
showRecordId?: boolean;
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
let?: Document;
/**
* 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.
* @deprecated Starting from MongoDB 4.4 this flag is not needed and will be ignored.
*/
oplogReplay?: boolean;
}

const SUPPORTS_WRITE_CONCERN_AND_COLLATION = 5;
Expand Down Expand Up @@ -242,6 +247,10 @@ function makeFindCommand(ns: MongoDBNamespace, filter: Document, options: FindOp
findCommand.tailable = options.tailable;
}

if (typeof options.oplogReplay === 'boolean') {
findCommand.oplogReplay = options.oplogReplay;
}

if (typeof options.timeout === 'boolean') {
findCommand.noCursorTimeout = !options.timeout;
} else if (typeof options.noCursorTimeout === 'boolean') {
Expand Down
69 changes: 69 additions & 0 deletions test/unit/operations/find.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { expect } from 'chai';
import * as sinon from 'sinon';
import { promisify } from 'util';

import { FindOperation } from '../../../src/operations/find';
import { Server } from '../../../src/sdam/server';
import { ServerDescription } from '../../../src/sdam/server_description';
import { Topology } from '../../../src/sdam/topology';
import { ns } from '../../../src/utils';

describe('FindOperation', function () {
const namespace = ns('db.coll');
const options = {
batchSize: 100
};
const filter = {
ts: { $gt: new Date() }
};

afterEach(function () {
sinon.restore();
});

describe('#constructor', function () {
const operation = new FindOperation(undefined, namespace, filter, options);

it('sets the namespace', function () {
expect(operation.ns).to.equal(namespace);
});

it('sets options', function () {
expect(operation.options).to.equal(options);
});

it('sets filter', function () {
expect(operation.filter).to.equal(filter);
});
});

describe('#execute', function () {
context('command construction', () => {
const namespace = ns('db.collection');
const server = new Server(new Topology([], {} as any), new ServerDescription(''), {} as any);

it('should build basic find command with filter', async () => {
const findOperation = new FindOperation(undefined, namespace, filter);
const stub = sinon.stub(server, 'command').yieldsRight();
await promisify(findOperation.execute.bind(findOperation))(server, undefined);
expect(stub).to.have.been.calledOnceWith(namespace, {
find: namespace.collection,
filter
});
});

it('should build find command with oplogReplay', async () => {
const options = {
oplogReplay: true
};
const findOperation = new FindOperation(undefined, namespace, {}, options);
const stub = sinon.stub(server, 'command').yieldsRight();
await promisify(findOperation.execute.bind(findOperation))(server, undefined);
expect(stub).to.have.been.calledOnceWith(
namespace,
sinon.match.has('oplogReplay', options.oplogReplay)
);
});
});
});
});

0 comments on commit 6c69b7d

Please sign in to comment.