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

feat(NODE-3793): Remove offensive language from code and tests #3082

Merged
merged 16 commits into from
Dec 17, 2021
12 changes: 6 additions & 6 deletions src/cmap/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let _requestId = 0;

// Query flags
const OPTS_TAILABLE_CURSOR = 2;
const OPTS_SLAVE = 4;
const OPTS_SECONDARY = 4;
const OPTS_OPLOG_REPLAY = 8;
const OPTS_NO_CURSOR_TIMEOUT = 16;
const OPTS_AWAIT_DATA = 32;
Expand Down Expand Up @@ -41,7 +41,7 @@ export interface OpQueryOptions extends CommandOptions {
ignoreUndefined?: boolean;
maxBsonSize?: number;
checkKeys?: boolean;
slaveOk?: boolean;
secondaryOk?: boolean;

requestId?: number;
moreToCome?: boolean;
Expand All @@ -67,7 +67,7 @@ export class Query {
checkKeys: boolean;
batchSize: number;
tailable: boolean;
slaveOk: boolean;
secondaryOk: boolean;
oplogReplay: boolean;
noCursorTimeout: boolean;
awaitData: boolean;
Expand Down Expand Up @@ -112,7 +112,7 @@ export class Query {

// Flags
this.tailable = false;
this.slaveOk = typeof options.slaveOk === 'boolean' ? options.slaveOk : false;
this.secondaryOk = typeof options.secondaryOk === 'boolean' ? options.secondaryOk : false;
this.oplogReplay = false;
this.noCursorTimeout = false;
this.awaitData = false;
Expand Down Expand Up @@ -146,8 +146,8 @@ export class Query {
flags |= OPTS_TAILABLE_CURSOR;
}

if (this.slaveOk) {
flags |= OPTS_SLAVE;
if (this.secondaryOk) {
flags |= OPTS_SECONDARY;
}

if (this.oplogReplay) {
Expand Down
6 changes: 3 additions & 3 deletions src/cmap/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export interface QueryOptions extends BSONSerializeOptions {
/** @internal */
export interface CommandOptions extends BSONSerializeOptions {
command?: boolean;
slaveOk?: boolean;
secondaryOk?: boolean;
/** Specify read preference if command supports it */
readPreference?: ReadPreferenceLike;
raw?: boolean;
Expand Down Expand Up @@ -427,7 +427,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
numberToReturn: -1,
checkKeys: false,
// This value is not overridable
slaveOk: readPreference.slaveOk()
secondaryOk: readPreference.secondaryOk()
},
options
);
Expand Down Expand Up @@ -472,7 +472,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
numberToReturn,
pre32Limit: typeof limit === 'number' ? limit : undefined,
checkKeys: false,
slaveOk: readPreference.slaveOk()
secondaryOk: readPreference.secondaryOk()
};

if (options.projection) {
Expand Down
9 changes: 7 additions & 2 deletions src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ export interface CollectionOptions
extends BSONSerializeOptions,
WriteConcernOptions,
LoggerOptions {
/**
* @deprecated Use secondaryOk instead
*/
slaveOk?: boolean;
secondaryOk?: boolean;
dariakp marked this conversation as resolved.
Show resolved Hide resolved
/** 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 All @@ -127,7 +131,7 @@ export interface CollectionPrivate {
namespace: MongoDBNamespace;
readPreference?: ReadPreference;
bsonOptions: BSONSerializeOptions;
slaveOk?: boolean;
secondaryOk?: boolean;
collectionHint?: Hint;
readConcern?: ReadConcern;
writeConcern?: WriteConcern;
Expand Down Expand Up @@ -182,7 +186,8 @@ export class Collection<TSchema extends Document = Document> {
bsonOptions: resolveBSONOptions(options, db),
readConcern: ReadConcern.fromOptions(options),
writeConcern: WriteConcern.fromOptions(options),
slaveOk: options == null || options.slaveOk == null ? db.slaveOk : options.slaveOk
secondaryOk:
options == null || options.secondaryOk == null ? db.secondaryOk : options.secondaryOk
};
}

Expand Down
12 changes: 11 additions & 1 deletion src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,18 @@ export class Db {
return this.s.options;
}

// slaveOk specified
/**
* slaveOk specified
dariakp marked this conversation as resolved.
Show resolved Hide resolved
* @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)
*/
get secondaryOk(): boolean {
return this.s.readPreference?.preference !== 'primary' || false;
}

Expand Down
16 changes: 12 additions & 4 deletions src/read_preference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,27 @@ export class ReadPreference {
}

/**
* Indicates that this readPreference needs the "slaveOk" bit when sent over the wire
*
* 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 {
const NEEDS_SLAVEOK = new Set<string>([
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
*/
secondaryOk(): boolean {
const NEEDS_SECONDARYOK = new Set<string>([
ReadPreference.PRIMARY_PREFERRED,
ReadPreference.SECONDARY,
ReadPreference.SECONDARY_PREFERRED,
ReadPreference.NEAREST
]);

return NEEDS_SLAVEOK.has(this.mode);
return NEEDS_SECONDARYOK.has(this.mode);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/functional/cursor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3752,7 +3752,7 @@ describe('Cursor', function () {
db.s.topology,
db.s.namespace,
{},
{ limit: 0, skip: 0, slaveOk: false, readPreference: 42 }
{ limit: 0, skip: 0, secondaryOk: false, readPreference: 42 }
dariakp marked this conversation as resolved.
Show resolved Hide resolved
);

cursor.hasNext(err => {
Expand Down