Skip to content

Commit a8a18c9

Browse files
author
Chris Cho
authored
DOCSP-22548: remove client.connect() from examples (#372)
1 parent 3de4e57 commit a8a18c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2
-118
lines changed

source/code-snippets/aggregation/agg.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ const uri = process.env.MONGDODB_URI;
33
const client = new MongoClient(uri);
44

55
async function run() {
6-
await client.connect();
7-
86
// begin data insertion
97
const db = client.db("aggregation");
108
const coll = db.collection("restaurants");

source/code-snippets/authentication/aws-env-variable.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ const client = new MongoClient(uri);
1313

1414
async function run() {
1515
try {
16-
// Connect the client to the server.
17-
await client.connect();
18-
1916
// Establish and verify connection.
2017
await client.db("admin").command({ ping: 1 });
2118
console.log("Connected successfully to server.");

source/code-snippets/authentication/aws.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ const client = new MongoClient(uri);
1919

2020
async function run() {
2121
try {
22-
// Connect the client to the server.
23-
await client.connect();
24-
2522
// Establish and verify connection.
2623
await client.db("admin").command({ ping: 1 });
2724
console.log("Connected successfully to server.");

source/code-snippets/authentication/cr.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ const client = new MongoClient(uri);
1515
// Function to connect to the server
1616
async function run() {
1717
try {
18-
// Connect the client to the server
19-
await client.connect();
20-
2118
// Establish and verify connection
2219
await client.db("admin").command({ ping: 1 });
2320
console.log("Connected successfully to server");

source/code-snippets/authentication/default.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ const client = new MongoClient(uri);
1717
// Function to connect to the server
1818
async function run() {
1919
try {
20-
// Connect the client to the server
21-
await client.connect();
22-
2320
// Establish and verify connection
2421
await client.db("admin").command({ ping: 1 });
2522
console.log("Connected successfully to server");

source/code-snippets/authentication/sha1.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ const client = new MongoClient(uri);
1717
// Function to connect to the server
1818
async function run() {
1919
try {
20-
// Connect the client to the server
21-
await client.connect();
22-
2320
// Establish and verify connection
2421
await client.db("admin").command({ ping: 1 });
2522
console.log("Connected successfully to server");

source/code-snippets/authentication/sha256.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ const client = new MongoClient(uri);
1717
// Function to connect to the server
1818
async function run() {
1919
try {
20-
// Connect the client to the server
21-
await client.connect();
22-
2320
// Establish and verify connection
2421
await client.db("admin").command({ ping: 1 });
2522
console.log("Connected successfully to server");

source/code-snippets/authentication/x509.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ const client = new MongoClient(uri);
1717
// Function to connect to the server
1818
async function run() {
1919
try {
20-
// Connect the client to the server
21-
await client.connect();
22-
2320
// Establish and verify connection
2421
await client.db("admin").command({ ping: 1 });
2522
console.log("Connected successfully to server");

source/code-snippets/connection/srv.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const client = new MongoClient(uri);
99

1010
async function run() {
1111
try {
12-
// Connect the client to the server
12+
// Connect the client to the server (optional starting in v4.7)
1313
await client.connect();
1414

1515
// Establish and verify connection

source/code-snippets/crud/arrayFilters.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ const client = new MongoClient(uri);
99

1010
async function loadData() {
1111
try {
12-
await client.connect();
13-
1412
const database = client.db("test");
1513
const pizza = database.collection("pizza");
1614

@@ -76,8 +74,6 @@ async function loadData() {
7674
async function runAllArrayElements() {
7775

7876
try {
79-
await client.connect();
80-
8177
const database = client.db("test");
8278
const pizza = database.collection("pizza");
8379

@@ -99,8 +95,6 @@ async function runAllArrayElements() {
9995
async function runFirstArrayElement() {
10096

10197
try {
102-
await client.connect();
103-
10498
const database = client.db("test");
10599
const pizza = database.collection("pizza");
106100

@@ -123,8 +117,6 @@ async function runFirstArrayElement() {
123117

124118
async function arrayFiltersOne() {
125119
try {
126-
await client.connect();
127-
128120
const database = client.db("test");
129121
const pizza = database.collection("pizza");
130122

@@ -154,8 +146,6 @@ async function arrayFiltersOne() {
154146

155147
async function arrayFiltersTwo() {
156148
try {
157-
await client.connect();
158-
159149
const database = client.db("test");
160150
const pizza = database.collection("pizza");
161151

0 commit comments

Comments
 (0)