Fix type of mongodb.connect (#27398)

It had never been updated from 2.x. Fixes #23548.
This commit is contained in:
Will Koster
2018-07-20 17:51:22 -07:00
committed by Wesley Wigham
parent f805351bd7
commit 5d63e04d34
2 changed files with 14 additions and 4 deletions
+3 -3
View File
@@ -24,9 +24,9 @@ import { ObjectID } from 'bson';
import { EventEmitter } from 'events';
import { Readable, Writable } from "stream";
export function connect(uri: string, options?: MongoClientOptions): Promise<Db>;
export function connect(uri: string, callback: MongoCallback<Db>): void;
export function connect(uri: string, options: MongoClientOptions, callback: MongoCallback<Db>): void;
export function connect(uri: string, options?: MongoClientOptions): Promise<MongoClient>;
export function connect(uri: string, callback: MongoCallback<MongoClient>): void;
export function connect(uri: string, options: MongoClientOptions, callback: MongoCallback<MongoClient>): void;
export { Binary, DBRef, Decimal128, Double, Long, MaxKey, MinKey, ObjectID, ObjectId, Timestamp } from 'bson';
+11 -1
View File
@@ -2,6 +2,8 @@
import mongodb = require('mongodb');
var MongoClient = mongodb.MongoClient;
const connectionString = 'mongodb://127.0.0.1:27017/test';
var format = require('util').format;
let options: mongodb.MongoClientOptions = {
authSource: ' ',
@@ -30,7 +32,7 @@ let options: mongodb.MongoClientOptions = {
promoteBuffers: false,
useNewUrlParser: false
}
MongoClient.connect('mongodb://127.0.0.1:27017/test', options, function (err: mongodb.MongoError, client: mongodb.MongoClient) {
MongoClient.connect(connectionString, options, function (err: mongodb.MongoError, client: mongodb.MongoClient) {
if (err) throw err;
const db = client.db('test');
var collection = db.collection('test_insert');
@@ -166,3 +168,11 @@ MongoClient.connect('mongodb://127.0.0.1:27017/test', options, function (err: mo
const res: mongodb.Cursor<TestCollection> = testCollection.find({ _id: 123 });
}
})
let testFunc = async () => {
let testClient: mongodb.MongoClient;
testClient = await mongodb.connect(connectionString);
};
mongodb.connect(connectionString, (err: mongodb.MongoError, client: mongodb.MongoClient) => {});
mongodb.connect(connectionString, options, (err: mongodb.MongoError, client: mongodb.MongoClient) => {});