Skip to content

Commit 8238837

Browse files
committed
respond to comments
1 parent cad85bc commit 8238837

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/operations/connect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export function connect(
199199

200200
// Has a connection already been established?
201201
if (mongoClient.topology && mongoClient.topology.isConnected()) {
202-
throw new MongoError(`'connect' cannot be called when already connected`);
202+
return callback(new MongoError('MongoClient is already connected'));
203203
}
204204

205205
let didRequestAuthentication = false;

test/functional/connection.test.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22
const { withClient, setupDatabase } = require('./shared');
3-
const test = require('./shared').assert,
4-
expect = require('chai').expect;
3+
const test = require('./shared').assert;
4+
const { expect } = require('chai');
55

66
describe('Connection', function () {
77
before(function () {
@@ -280,8 +280,8 @@ it(
280280
withClient(function (client, done) {
281281
expect(client.isConnected()).to.be.true;
282282

283-
const collection = client.db('testReconnect').collection('test');
284-
collection.insertOne({ a: 1 }, (err, result) => {
283+
const collection = client.db('shouldConnectAfterClose').collection('test');
284+
collection.insertOne({ a: 1, b: 2 }, (err, result) => {
285285
expect(err).to.not.exist;
286286
expect(result).to.exist;
287287

@@ -293,9 +293,11 @@ it(
293293
expect(err).to.not.exist;
294294
expect(client.isConnected()).to.be.true;
295295

296-
collection.insertOne({ b: 2 }, (err, result) => {
296+
collection.findOne({ a: 1 }, (err, result) => {
297297
expect(err).to.not.exist;
298298
expect(result).to.exist;
299+
expect(result).to.have.property('a', 1);
300+
expect(result).to.have.property('b', 2);
299301
expect(client.topology.isDestroyed()).to.be.false;
300302
done();
301303
});

0 commit comments

Comments
 (0)