Ticket connection Error

FAIL test/db-connection.test.js
● Test suite failed to run

TypeError: Cannot read property 'close' of undefined

  17 | 
  18 |   async teardown() {
> 19 |     await this.global.mflixClient.close()
     |                                   ^
  20 |     await super.teardown()
  21 |   }
  22 | 

  at MongoEnvironment.teardown (test/config/mongoEnvironment.js:19:35)
      at Generator.throw (<anonymous>)

Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.391s
Ran all test suites matching /db-connection/i.
Teardown Mongo Connection
npm ERR! Test failed. See above for more details.

1 Like

Please recheck your connection string. If it still does not resolve, share it here.

Kanika

i have a problem with connecting to the cluster
connecting to: mongodb://10.10.10.15:27001,10.10.10.16:27002,10.10.10.17:27000/mflix?replicaSet=replicaSe

2019-05-20T18:16:21.309+0530 I NETWORK [thread1] Starting new replica set monitor for replicaSe/10.10.10.15:27001,10.10.10.16:27002,10.10.10.17:27000

2019-05-20T18:16:26.316+0530 W NETWORK [thread1] Failed to connect to 10.10.10.17:27000 after 5000ms milliseconds, giving up.

2019-05-20T18:16:26.316+0530 W NETWORK [ReplicaSetMonitor-TaskExecutor-0] Failed to connect to 10.10.10.15:27001 after 5000ms milliseconds, giving up.

2019-05-20T18:16:31.320+0530 W NETWORK [thread1] Failed to connect to 10.10.10.16:27002 after 5000ms milliseconds, giving up.

2019-05-20T18:16:31.320+0530 W NETWORK [thread1] Unable to reach primary for set replicaSe

2019-05-20T18:16:31.320+0530 I NETWORK [thread1] Cannot reach any nodes for set replicaSe. Please check network connectivity and the status of the set. This has happened for 1 checks in a row.

2019-05-20T18:16:36.827+0530 W NETWORK [thread1] Failed to connect to 10.10.10.16:27002 after 5000ms milliseconds, giving up.

2019-05-20T18:16:41.827+0530 W NETWORK [thread1] Failed to connect to 10.10.10.17:27000 after 5000ms milliseconds, giving up.

2019-05-20T18:16:46.829+0530 W NETWORK [thread1] Failed to connect to 10.10.10.15:27001 after 5000ms milliseconds, giving up.

2019-05-20T18:16:46.829+0530 W NETWORK [thread1] Unable to reach primary for set replicaSe

2019-05-20T18:16:46.829+0530 I NETWORK [thread1] Cannot reach any nodes for set replicaSe. Please check network connectivity and the status of the set. This has happened for 2 checks in a row.

2019-05-20T18:16:46.830+0530 E QUERY [thread1] Error: connect failed to replica set replicaSe/10.10.10.15:27001,10.10.10.16:27002,10.10.10.17:27000 :

connect@src/mongo/shell/mongo.js:251:13

@(connect):1:6

exception: connect failed
these are the error araising

Please share the connection string you are using to connect.

Kanika

mongo “mongodb+srv://mflix-1dkeu.mongodb.net/test” --username m220student this is the string

Hi @aparna4,

The connection string seems fine. Please make sure you have IP whitelisted.

Steps from cloud.mongodb.com:

Security -> IP whitelist -> Add IP address

Kanika

yup i have added ip address it will connect from everywhere

connecting to: mongodb+srv://mflix-1dkeu.mongodb.net/test

2019-05-20T20:07:12.011+0530 I NETWORK [js] Starting new replica set monitor for mflix-shard-0/mflix-shard-00-00-1dkeu.mongodb.net.:27017,mflix-shard-00-01-1dkeu.mongodb.net.:27017,mflix-shard-00-02-1dkeu.mongodb.net.:27017

2019-05-20T20:07:12.172+0530 I NETWORK [js] Successfully connected to mflix-shard-00-00-1dkeu.mongodb.net.:27017 (1 connections now open to mflix-shard-00-00-1dkeu.mongodb.net.:27017 with a 5 second timeout)

2019-05-20T20:07:12.177+0530 I NETWORK [ReplicaSetMonitor-TaskExecutor] Successfully connected to mflix-shard-00-01-1dkeu.mongodb.net.:27017 (1 connections now open to mflix-shard-00-01-1dkeu.mongodb.net.:27017 with a 5 second timeout)

2019-05-20T20:07:12.208+0530 I NETWORK [js] changing hosts to mflix-shard-0/mflix-shard-00-00-1dkeu.mongodb.net:27017,mflix-shard-00-01-1dkeu.mongodb.net:27017,mflix-shard-00-02-1dkeu.mongodb.net:27017 from mflix-shard-0/mflix-shard-00-00-1dkeu.mongodb.net.:27017,mflix-shard-00-01-1dkeu.mongodb.net.:27017,mflix-shard-00-02-1dkeu.mongodb.net.:27017

2019-05-20T20:07:12.356+0530 I NETWORK [js] Successfully connected to mflix-shard-00-00-1dkeu.mongodb.net:27017 (1 connections now open to mflix-shard-00-00-1dkeu.mongodb.net:27017 with a 5 second timeout)

2019-05-20T20:07:12.363+0530 I NETWORK [ReplicaSetMonitor-TaskExecutor] Successfully connected to mflix-shard-00-01-1dkeu.mongodb.net:27017 (1 connections now open to mflix-shard-00-01-1dkeu.mongodb.net:27017 with a 5 second timeout)

Implicit session: session { “id” : UUID(“e5c497f8-63e0-4c21-bf7d-d7ffd0b27a33”) }

2019-05-20T20:07:12.583+0530 I NETWORK [ReplicaSetMonitor-TaskExecutor] Successfully connected to mflix-shard-00-02-1dkeu.mongodb.net:27017 (1 connections now open to mflix-shard-00-02-1dkeu.mongodb.net:27017 with a 5 second timeout)

MongoDB server version: 4.0.9

2019-05-20T20:07:12.715+0530 I NETWORK [js] Marking host mflix-shard-00-00-1dkeu.mongodb.net:27017 as failed :: caused by :: Location8000: can’t authenticate against replica set node mflix-shard-00-00-1dkeu.mongodb.net:27017 :: caused by :: bad auth Authentication failed.

2019-05-20T20:07:12.771+0530 I NETWORK [js] Marking host mflix-shard-00-02-1dkeu.mongodb.net:27017 as failed :: caused by :: SocketException: can’t authenticate against replica set node mflix-shard-00-02-1dkeu.mongodb.net:27017 :: caused by :: socket exception [CONNECT_ERROR] server [mflix-shard-00-02-1dkeu.mongodb.net:27017] connection pool error: network error while attempting to run command ‘isMaster’ on host ‘mflix-shard-00-02-1dkeu.mongodb.net:27017

2019-05-20T20:07:12.822+0530 I NETWORK [js] Marking host mflix-shard-00-01-1dkeu.mongodb.net:27017 as failed :: caused by :: SocketException: can’t authenticate against replica set node mflix-shard-00-01-1dkeu.mongodb.net:27017 :: caused by :: socket exception [CONNECT_ERROR] server [mflix-shard-00-01-1dkeu.mongodb.net:27017] connection pool error: network error while attempting to run command ‘isMaster’ on host ‘mflix-shard-00-01-1dkeu.mongodb.net:27017

2019-05-20T20:07:12.906+0530 I NETWORK [js] Marking host mflix-shard-00-00-1dkeu.mongodb.net:27017 as failed :: caused by :: Location8000: can’t authenticate against replica set node mflix-shard-00-00-1dkeu.mongodb.net:27017 :: caused by :: bad auth Authentication failed.

2019-05-20T20:07:12.906+0530 E QUERY [js] Error: can’t authenticate against replica set node mflix-shard-00-00-1dkeu.mongodb.net:27017 :: caused by :: bad auth Authentication failed. :

DB.prototype._authOrThrow@src/mongo/shell/db.js:1685:20

@(auth):6:1

@(auth):1:2

exception: login failed

Hi @aparna4,

Please check your username/password which you are using to connect.

The following connection string worked for me:

 mongo "mongodb+srv://m220student:m220password@mflix-1dkeu.mongodb.net/test"

24%20PM

Kanika

i got it thank you sooo much:))

1 Like

Hello guys, I have the same issue
when i run:
npm test -t db-connection
how do I solve this?

can u send the screenshot of the error

1 Like

C:\Users\Techpatriate zaza\Desktop\mongodb>npm test -t db-connection

server@1.0.0 test C:\Users\Techpatriate zaza\Desktop\mongodb
jest --passWithNoTests “db-connection”

Determining test suites to run…Setup Mongo Connection
FAIL test/db-connection.test.js (8.397s)
Connection
√ Can access MFlix data (879ms)
x Can retrieve a movie by id (349ms)
x Can retrieve first page of movies (1518ms)

? Connection > Can retrieve a movie by id

TypeError: Cannot read property 'title' of null

  18 |     const id = "573a13a6f29313caabd17bd5"
  19 |     const movie = await MoviesDAO.getMovieByID(id)
> 20 |     expect(movie.title).toEqual("Once Upon a Time in Mexico")
     |                  ^
  21 |   })
  22 |
  23 |   test("Can retrieve first page of movies", async () => {

  at title (test/db-connection.test.js:20:18)
  at tryCatch (node_modules/regenerator-runtime/runtime.js:62:40)
  at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime

.js:296:22)
at Generator.prototype.(anonymous function) [as next] (node_modules/regene
rator-runtime/runtime.js:114:21)
at step (node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
at node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13

? Connection > Can retrieve first page of movies

expect(received).toEqual(expected)

Expected value to equal:
  45993
Received:
  4000

  27 |     } = await MoviesDAO.getMovies()
  28 |     expect(firstPage.length).toEqual(20)
> 29 |     expect(numMovies).toEqual(45993)
     |                       ^
  30 |   })
  31 | })
  32 |

  at toEqual (test/db-connection.test.js:29:23)
  at tryCatch (node_modules/regenerator-runtime/runtime.js:62:40)
  at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime

.js:296:22)
at Generator.prototype.(anonymous function) [as next] (node_modules/regene
rator-runtime/runtime.js:114:21)
at step (node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
at node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13

Test Suites: 1 failed, 1 total
Tests: 2 failed, 1 passed, 3 total
Snapshots: 0 total
Time: 9.533s, estimated 11s
Ran all test suites matching /db-connection/i.
Teardown Mongo Connection
npm ERR! Test failed. See above for more details.

I just sent a screenshot now with the error messages, have you seen it?

mongo “mongodb+srv://m220student:m220password@mflix-1dkeu.mongodb.net/test” just run this command


This is what I got?

Try to run the command which I gave in the previous reply

I already did that, and that is the screenshot I sent to you :arrow_up: didn’t you see that?

remove --username m220student and then run

Please use the below command. You might be using character l [L] instead it is number 1 in connection string:

mongo mongodb+srv://m220student:m220password@mflix-1dkeu.mongodb.net/test

It is 1dkeu.mongodb.net.

Kanika