Skip to content

feat(NODE-3818)!: remove slaveOk options #3503

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

Merged
merged 4 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions etc/notes/CHANGES_5.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ The following is a detailed collection of the changes in the major v5 release of

## Changes

### salveOk options removed

The deprecated `slaveOk` option and `slaveOk()` method on the `Collection` class have been removed. Please
now use `secondaryOk` as the replacement for the option and the method.

### Snappy v7.x.x or later and optional peerDependency

`snappy` compression has been added to the package.json as a peerDependency that is **optional**.
Expand Down
4 changes: 0 additions & 4 deletions src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ export interface CollectionOptions
extends BSONSerializeOptions,
WriteConcernOptions,
LoggerOptions {
/**
* @deprecated Use readPreference instead
*/
slaveOk?: boolean;
/** Specify a read concern for the collection. (only MongoDB 3.2 or higher supported) */
readConcern?: ReadConcernLike;
/** The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). */
Expand Down
8 changes: 0 additions & 8 deletions src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,6 @@ export class Db {
return this.s.options;
}

/**
* slaveOk specified
* @deprecated Use secondaryOk instead
*/
get slaveOk(): boolean {
return this.secondaryOk;
}

/**
* Check if a secondary can be used (because the read preference is *not* set to primary)
*/
Expand Down
9 changes: 0 additions & 9 deletions src/read_preference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,6 @@ export class ReadPreference {
return ReadPreference.isValid(typeof mode === 'string' ? mode : this.mode);
}

/**
* Indicates that this readPreference needs the "secondaryOk" bit when sent over the wire
* @deprecated Use secondaryOk instead
* @see https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/#op-query
*/
slaveOk(): boolean {
return this.secondaryOk();
}

/**
* Indicates that this readPreference needs the "SecondaryOk" bit when sent over the wire
* @see https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/#op-query
Expand Down
6 changes: 0 additions & 6 deletions test/unit/db.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,41 @@ import { ReadPreference } from '../../src/read_preference';
describe('class Db', function () {
describe('secondaryOk', function () {
const client = new MongoClient('mongodb://localhost:27017');
const legacy_secondary_ok = 'slaveOk';
const secondary_ok = 'secondaryOk';

it('should be false when readPreference is Primary', function () {
const options: DbOptions = { readPreference: ReadPreference.PRIMARY };
const mydb = new Db(client, 'mydb', options);

expect(mydb).property(secondary_ok).to.be.false;
expect(mydb).property(legacy_secondary_ok).to.be.false;
});

it('should be true when readPreference is Primary Preferred', function () {
const options: DbOptions = { readPreference: ReadPreference.PRIMARY_PREFERRED };
const mydb = new Db(client, 'mydb', options);

expect(mydb).property(secondary_ok).to.be.true;
expect(mydb).property(legacy_secondary_ok).to.be.true;
});

it('should be true when readPreference is Secondary', function () {
const options: DbOptions = { readPreference: ReadPreference.SECONDARY };
const mydb = new Db(client, 'mydb', options);

expect(mydb).property(secondary_ok).to.be.true;
expect(mydb).property(legacy_secondary_ok).to.be.true;
});

it('should be true when readPreference is Secondary Preferred', function () {
const options: DbOptions = { readPreference: ReadPreference.SECONDARY_PREFERRED };
const mydb = new Db(client, 'mydb', options);

expect(mydb).property(secondary_ok).to.be.true;
expect(mydb).property(legacy_secondary_ok).to.be.true;
});

it('should be true when readPreference is Nearest', function () {
const options: DbOptions = { readPreference: ReadPreference.NEAREST };
const mydb = new Db(client, 'mydb', options);

expect(mydb).property(secondary_ok).to.be.true;
expect(mydb).property(legacy_secondary_ok).to.be.true;
});
});
});
5 changes: 0 additions & 5 deletions test/unit/read_preference.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,39 +139,34 @@ describe('class ReadPreference', function () {
readPreference: PRIMARY
});
expect(readPreference.secondaryOk()).to.be.false;
expect(readPreference.slaveOk()).to.be.false;
});

it('should be true when readPreference is Primary Preferred', function () {
const readPreference = ReadPreference.fromOptions({
readPreference: PRIMARY_PREFERRED
});
expect(readPreference.secondaryOk()).to.be.true;
expect(readPreference.slaveOk()).to.be.true;
});

it('should be true when readPreference is Secondary', function () {
const readPreference = ReadPreference.fromOptions({
readPreference: SECONDARY
});
expect(readPreference.secondaryOk()).to.be.true;
expect(readPreference.slaveOk()).to.be.true;
});

it('should be true when readPreference is Secondary Preferred', function () {
const readPreference = ReadPreference.fromOptions({
readPreference: SECONDARY_PREFERRED
});
expect(readPreference.secondaryOk()).to.be.true;
expect(readPreference.slaveOk()).to.be.true;
});

it('should be true when readPreference is Nearest', function () {
const readPreference = ReadPreference.fromOptions({
readPreference: NEAREST
});
expect(readPreference.secondaryOk()).to.be.true;
expect(readPreference.slaveOk()).to.be.true;
});
});
});