Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NODE-4467): Add back support for oplogReplay option as deprecated #3337

Merged
merged 2 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
);
});
});
});
});