Skip to content

Commit 8ae3505

Browse files
committed
Merge remote-tracking branch 'origin/4.0' into NODE-3056/4.0/fix-aws-auth-test
2 parents 17b2040 + 1615be0 commit 8ae3505

29 files changed

+1636
-1275
lines changed

HISTORY.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [4.0.0-beta.1](https://github.com/mongodb/node-mongodb-native/compare/v4.0.0-beta.0...v4.0.0-beta.1) (2021-02-02)
6+
7+
8+
### Bug Fixes
9+
10+
* **find:** correctly translate timeout option into noCursorTimeout ([#2708](https://github.com/mongodb/node-mongodb-native/issues/2708)) ([16a22c4](https://github.com/mongodb/node-mongodb-native/commit/16a22c4688bd1b4fba83fe54ea4eb24b7778eb86))
11+
* Compatibility with mongodb-client-encryption ([#2713](https://github.com/mongodb/node-mongodb-native/issues/2713)) ([d08ddb9](https://github.com/mongodb/node-mongodb-native/commit/d08ddb95984606c681b781052827e40ccdc8ef3d))
12+
* restore `createAutoEncrypter()` functionality ([#2710](https://github.com/mongodb/node-mongodb-native/issues/2710)) ([25ef870](https://github.com/mongodb/node-mongodb-native/commit/25ef87026bca935b00d30ad943ddd28784f801e8))
13+
* Support bson property on Topology class ([#2721](https://github.com/mongodb/node-mongodb-native/issues/2721)) ([00b1374](https://github.com/mongodb/node-mongodb-native/commit/00b1374454f5614879a5ecec5b4aae871e31222c))
14+
* Use getters to sync BulkWriteResult wrappers ([#2716](https://github.com/mongodb/node-mongodb-native/issues/2716)) ([c94b54a](https://github.com/mongodb/node-mongodb-native/commit/c94b54ad35dfe65d45f730f9e78169d169608a34))
15+
* **operations:** avoid hardcoding `checkKeys` for insert operations ([#2726](https://github.com/mongodb/node-mongodb-native/issues/2726)) ([5ce9b25](https://github.com/mongodb/node-mongodb-native/commit/5ce9b25c965e2be633bf4095647e73a152d9914c))
16+
* **operations:** make every CollationOptions property optional except `locale` ([#2727](https://github.com/mongodb/node-mongodb-native/issues/2727)) ([8a678e9](https://github.com/mongodb/node-mongodb-native/commit/8a678e9f1d323700773ab2530a137f0346036dce))
17+
* **WriteConcern:** avoid throwing error when options is null ([#2714](https://github.com/mongodb/node-mongodb-native/issues/2714)) ([ea142bc](https://github.com/mongodb/node-mongodb-native/commit/ea142bc78ce9f6b2b97fd8998734d3d698aa2f38))
18+
519
## [4.0.0-beta.0](https://github.com/mongodb/node-mongodb-native/compare/v3.5.4...v4.0.0-beta.0) (2021-01-19)
620

721

package-lock.json

Lines changed: 591 additions & 510 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mongodb",
3-
"version": "4.0.0-beta.0",
3+
"version": "4.0.0-beta.1",
44
"description": "The official MongoDB driver for Node.js",
55
"main": "lib/index.js",
66
"files": [
@@ -70,7 +70,7 @@
7070
"sinon-chai": "^3.2.0",
7171
"snappy": "^6.3.0",
7272
"source-map-support": "^0.5.19",
73-
"standard-version": "^7.1.0",
73+
"standard-version": "^8.0.2",
7474
"through2": "^3.0.1",
7575
"ts-node": "^9.0.0",
7676
"typedoc": "^0.20.14",

src/cursor/aggregation_cursor.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { AggregateOperation, AggregateOptions } from '../operations/aggregate';
22
import { AbstractCursor, assertUninitialized } from './abstract_cursor';
33
import { executeOperation, ExecutionResult } from '../operations/execute_operation';
4+
import { mergeOptions } from '../utils';
45
import type { Document } from '../bson';
56
import type { Sort } from '../sort';
67
import type { Topology } from '../sdam/topology';
@@ -52,9 +53,9 @@ export class AggregationCursor extends AbstractCursor {
5253
}
5354

5455
clone(): AggregationCursor {
56+
const clonedOptions = mergeOptions({}, this[kOptions]);
5557
return new AggregationCursor(this[kParent], this.topology, this.namespace, this[kPipeline], {
56-
...this[kOptions],
57-
...this.cursorOptions
58+
...clonedOptions
5859
});
5960
}
6061

src/cursor/find_cursor.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { ExplainVerbosityLike } from '../explain';
44
import { CountOperation, CountOptions } from '../operations/count';
55
import { executeOperation, ExecutionResult } from '../operations/execute_operation';
66
import { FindOperation, FindOptions } from '../operations/find';
7+
import { mergeOptions } from '../utils';
78
import type { Hint } from '../operations/operation';
89
import type { CollationOptions } from '../operations/command';
910
import type { Topology } from '../sdam/topology';
@@ -52,9 +53,9 @@ export class FindCursor extends AbstractCursor {
5253
}
5354

5455
clone(): FindCursor {
56+
const clonedOptions = mergeOptions({}, this[kBuiltOptions]);
5557
return new FindCursor(this.topology, this.namespace, this[kFilter], {
56-
...this[kBuiltOptions],
57-
...this.cursorOptions
58+
...clonedOptions
5859
});
5960
}
6061

src/operations/command.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ const SUPPORTS_WRITE_CONCERN_AND_COLLATION = 5;
1616
/** @public */
1717
export interface CollationOptions {
1818
locale: string;
19-
caseLevel: boolean;
20-
caseFirst: string;
21-
strength: number;
22-
numericOrdering: boolean;
23-
alternate: string;
24-
maxVariable: string;
25-
backwards: boolean;
19+
caseLevel?: boolean;
20+
caseFirst?: string;
21+
strength?: number;
22+
numericOrdering?: boolean;
23+
alternate?: string;
24+
maxVariable?: string;
25+
backwards?: boolean;
26+
normalization?: boolean;
2627
}
2728

2829
/** @public */

src/operations/insert.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class InsertOperation extends CommandOperation<Document> {
1818

1919
constructor(ns: MongoDBNamespace, documents: Document[], options: BulkWriteOptions) {
2020
super(undefined, options);
21-
this.options = { ...options, checkKeys: true };
21+
this.options = { ...options, checkKeys: options.checkKeys ?? true };
2222
this.ns = ns;
2323
this.documents = documents;
2424
}

src/sdam/topology_description.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,29 @@ export class TopologyDescription {
9595
// value among ServerDescriptions of all data-bearing server types. If any have a null
9696
// logicalSessionTimeoutMinutes, then TopologyDescription.logicalSessionTimeoutMinutes MUST be
9797
// set to null.
98-
const readableServers = Array.from(this.servers.values()).filter(
99-
(s: ServerDescription) => s.isReadable
100-
);
101-
102-
this.logicalSessionTimeoutMinutes = readableServers.reduce(
103-
(result: number | undefined, server: ServerDescription) => {
104-
if (server.logicalSessionTimeoutMinutes == null) return;
105-
if (result == null) return server.logicalSessionTimeoutMinutes;
106-
return Math.min(result, server.logicalSessionTimeoutMinutes);
107-
},
108-
undefined
109-
);
98+
this.logicalSessionTimeoutMinutes = undefined;
99+
for (const [, server] of this.servers) {
100+
if (server.isReadable) {
101+
if (server.logicalSessionTimeoutMinutes == null) {
102+
// If any of the servers have a null logicalSessionsTimeout, then the whole topology does
103+
this.logicalSessionTimeoutMinutes = undefined;
104+
break;
105+
}
106+
107+
if (this.logicalSessionTimeoutMinutes === undefined) {
108+
// First server with a non null logicalSessionsTimeout
109+
this.logicalSessionTimeoutMinutes = server.logicalSessionTimeoutMinutes;
110+
continue;
111+
}
112+
113+
// Always select the smaller of the:
114+
// current server logicalSessionsTimeout and the topologies logicalSessionsTimeout
115+
this.logicalSessionTimeoutMinutes = Math.min(
116+
this.logicalSessionTimeoutMinutes,
117+
server.logicalSessionTimeoutMinutes
118+
);
119+
}
120+
}
110121
}
111122

112123
/**

test/functional/client_side_encryption/corpus.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ const fs = require('fs');
66
const path = require('path');
77
const BSON = require('bson');
88
const { EJSON } = require('bson');
9-
const chai = require('chai');
10-
const expect = chai.expect;
11-
chai.config.includeStack = true;
12-
chai.config.showDiff = true;
13-
chai.config.truncateThreshold = 0;
9+
const { expect } = require('chai');
1410

1511
describe('Client Side Encryption Corpus', function () {
1612
const metadata = {

test/functional/client_side_encryption/driver.test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ const crypto = require('crypto');
44
const BSON = require('bson');
55
const chai = require('chai');
66
const expect = chai.expect;
7-
chai.config.includeStack = true;
8-
chai.config.showDiff = true;
9-
chai.config.truncateThreshold = 0;
107
chai.use(require('chai-subset'));
118

129
describe('Client Side Encryption Functional', function () {

test/functional/collection.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,16 @@ describe('Collection', function () {
269269
});
270270
});
271271

272+
it('should permit insert of dot and dollar keys if requested', function () {
273+
const collection = db.collection('test_invalid_key_names');
274+
return Promise.all([
275+
collection.insertOne({ hel$lo: 0 }, { checkKeys: false }),
276+
collection.insertOne({ hello: { $hello: 0 } }, { checkKeys: false }), // embedded document can have a leading dollar
277+
collection.insertOne({ 'hel.lo': 0 }, { checkKeys: false }),
278+
collection.drop()
279+
]);
280+
});
281+
272282
it('should fail due to illegal listCollections', function (done) {
273283
db.collection(5, err => {
274284
expect(err.message).to.equal('collection name must be a String');

test/functional/connection.test.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ describe('Connection - functional', function () {
144144
metadata: { requires: { topology: 'single' } },
145145

146146
test: function (done) {
147-
var configuration = this.configuration;
148-
var user = 'testConnectGoodAuth',
149-
password = 'password';
147+
const configuration = this.configuration;
148+
const username = 'testConnectGoodAuth';
149+
const password = 'password';
150150

151151
const setupClient = configuration.newClient();
152152

@@ -155,14 +155,14 @@ describe('Connection - functional', function () {
155155
expect(err).to.not.exist;
156156
var db = client.db(configuration.db);
157157

158-
db.addUser(user, password, function (err) {
158+
db.addUser(username, password, function (err) {
159159
expect(err).to.not.exist;
160160
client.close(restOfTest);
161161
});
162162
});
163163

164164
function restOfTest() {
165-
const testClient = configuration.newClient(configuration.url(user, password));
165+
const testClient = configuration.newClient(configuration.url({ username, password }));
166166
testClient.connect(
167167
connectionTester(configuration, 'testConnectGoodAuth', function (client) {
168168
client.close(done);
@@ -176,7 +176,7 @@ describe('Connection - functional', function () {
176176
metadata: { requires: { topology: 'single' } },
177177

178178
test: function (done) {
179-
var configuration = this.configuration;
179+
const configuration = this.configuration;
180180
const username = 'testConnectGoodAuthAsOption';
181181
const password = 'password';
182182

@@ -211,7 +211,9 @@ describe('Connection - functional', function () {
211211

212212
test: function (done) {
213213
var configuration = this.configuration;
214-
const client = configuration.newClient(configuration.url('slithy', 'toves'));
214+
const client = configuration.newClient(
215+
configuration.url({ username: 'slithy', password: 'toves' })
216+
);
215217
client.connect(function (err, client) {
216218
expect(err).to.exist;
217219
expect(client).to.not.exist;

test/functional/cursor.test.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3755,6 +3755,65 @@ describe('Cursor', function () {
37553755
}
37563756
);
37573757

3758+
describe('#clone', function () {
3759+
let client;
3760+
let db;
3761+
let collection;
3762+
3763+
beforeEach(function () {
3764+
client = this.configuration.newClient({ w: 1 });
3765+
3766+
return client.connect().then(client => {
3767+
db = client.db(this.configuration.db);
3768+
collection = db.collection('test_coll');
3769+
});
3770+
});
3771+
3772+
afterEach(function () {
3773+
return client.close();
3774+
});
3775+
3776+
context('when executing on a find cursor', function () {
3777+
it('removes the existing session from the cloned cursor', function () {
3778+
const docs = [{ name: 'test1' }, { name: 'test2' }];
3779+
return collection.insertMany(docs).then(() => {
3780+
const cursor = collection.find({}, { batchSize: 1 });
3781+
return cursor
3782+
.next()
3783+
.then(doc => {
3784+
expect(doc).to.exist;
3785+
const clonedCursor = cursor.clone();
3786+
expect(clonedCursor.cursorOptions.session).to.not.exist;
3787+
expect(clonedCursor.session).to.not.exist;
3788+
})
3789+
.finally(() => {
3790+
return cursor.close();
3791+
});
3792+
});
3793+
});
3794+
});
3795+
3796+
context('when executing on an aggregation cursor', function () {
3797+
it('removes the existing session from the cloned cursor', function () {
3798+
const docs = [{ name: 'test1' }, { name: 'test2' }];
3799+
return collection.insertMany(docs).then(() => {
3800+
const cursor = collection.aggregate([{ $match: {} }], { batchSize: 1 });
3801+
return cursor
3802+
.next()
3803+
.then(doc => {
3804+
expect(doc).to.exist;
3805+
const clonedCursor = cursor.clone();
3806+
expect(clonedCursor.cursorOptions.session).to.not.exist;
3807+
expect(clonedCursor.session).to.not.exist;
3808+
})
3809+
.finally(() => {
3810+
return cursor.close();
3811+
});
3812+
});
3813+
});
3814+
});
3815+
});
3816+
37583817
it('should return a promise when no callback supplied to forEach method', function () {
37593818
const configuration = this.configuration;
37603819
const client = configuration.newClient({ w: 1 }, { maxPoolSize: 1 });

test/functional/spec-runner/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ function promiseTry(callback) {
2121

2222
chai.use(require('chai-subset'));
2323
chai.use(require('./matcher').default);
24-
chai.config.includeStack = true;
25-
chai.config.showDiff = true;
26-
chai.config.truncateThreshold = 0;
2724

2825
function escape(string) {
2926
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');

test/functional/spec-runner/matcher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ function matchMongoSpec(chai, utils) {
187187
'expected #{act} to not match spec #{exp}',
188188
result.expected,
189189
result.actual,
190-
chai.config.showDiff
190+
chai.config.showDiff || true
191191
);
192192
});
193193

test/functional/spec-runner/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
function resolveConnectionString(configuration, spec, context) {
44
const isShardedEnvironment = configuration.topologyType === 'Sharded';
55
const useMultipleMongoses = spec && !!spec.useMultipleMongoses;
6-
const user = context && context.user;
6+
const username = context && context.user;
77
const password = context && context.password;
88
const authSource = context && context.authSource;
99
const connectionString =
1010
isShardedEnvironment && !useMultipleMongoses
1111
? `mongodb://${configuration.host}:${configuration.port}/${
1212
configuration.db
1313
}?directConnection=false${authSource ? '&authSource=${authSource}' : ''}`
14-
: configuration.url(user, password, { authSource });
14+
: configuration.url({ username, password, authSource });
1515
return connectionString;
1616
}
1717

0 commit comments

Comments
 (0)