Skip to content
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
11 changes: 10 additions & 1 deletion src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,16 @@ export class Collection {
options?: InsertOneOptions | Callback<InsertOneResult>,
callback?: Callback<InsertOneResult>
): Promise<InsertOneResult> | void {
if (typeof options === 'function') (callback = options), (options = {});
if (typeof options === 'function') {
callback = options;
options = {};
}

// CSFLE passes in { w: 'majority' } to ensure the lib works in both 3.x and 4.x
// we support that option style here only
if (options && Reflect.get(options, 'w')) {
options.writeConcern = WriteConcern.fromOptions(Reflect.get(options, 'w'));
}
Comment on lines +286 to +290
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here that is just checking for the legacy writeConcern shape


return executeOperation(
getTopology(this),
Expand Down
7 changes: 5 additions & 2 deletions src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ export function parseOptions(

checkTLSOptions(mongoOptions);
if (mongoClient && options.autoEncryption) {
mongoOptions.autoEncrypter = createAutoEncrypter(mongoClient, options);
mongoOptions.autoEncrypter = createAutoEncrypter(mongoClient, mongoOptions);
}
if (options.promiseLibrary) PromiseProvider.set(options.promiseLibrary);

Expand Down Expand Up @@ -1062,7 +1062,10 @@ export const OPTIONS = {
passphrase: { type: 'any' },
pfx: { type: 'any' },
secureProtocol: { type: 'any' },
index: { type: 'any' }
index: { type: 'any' },
// Legacy Options, these are unused but left here to avoid errors with CSFLE lib
useNewUrlParser: { type: 'boolean' } as OptionDescriptor,
useUnifiedTopology: { type: 'boolean' } as OptionDescriptor
Comment on lines +1067 to +1068
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here that's supporting the old options. These still aren't listed in the props for MongoClientOptions (which is why we have the as casting). I would add that they are deprecated but then our CSFLE lib would emit the warnings with no way to disable.

} as Record<keyof MongoClientOptions, OptionDescriptor>;

export const DEFAULT_OPTIONS = new CaseInsensitiveMap(
Expand Down
4 changes: 2 additions & 2 deletions src/operations/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { resolveSRVRecord } from '../connection_string';
import { emitDeprecationWarning, Callback } from '../utils';
import { CMAP_EVENT_NAMES } from '../cmap/events';
import * as BSON from '../bson';
import type { MongoClient, MongoOptions, MongoClientOptions } from '../mongo_client';
import type { MongoClient, MongoOptions } from '../mongo_client';
import { Connection } from '../cmap/connection';
import { Server } from '../sdam/server';
import type { AutoEncrypter } from '../deps';
Expand Down Expand Up @@ -116,7 +116,7 @@ function registerDeprecatedEventNotifiers(client: MongoClient) {
*/
export function createAutoEncrypter(
client: MongoClient,
options: MongoClientOptions
options: MongoOptions
): AutoEncrypter | undefined {
if (!options.autoEncryption) {
return;
Expand Down
2 changes: 1 addition & 1 deletion test/tools/runner/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class TestConfiguration {
} else {
multipleHosts = this.options.hostAddresses
.reduce((built, host) => {
built.push(host.type === 'tcp' ? `${host.host}:${host.port}` : host.host);
built.push(typeof host.port === 'number' ? `${host.host}:${host.port}` : host.host);
return built;
}, [])
.join(',');
Expand Down