Ticket:Connection: Access Error

I am getting this error while trying to run the test.
Determining test suites to run…Setup Mongo Connection
(node:5864) Warning: Accessing non-existent property ‘count’ of module exports inside circular dependency
(Use node --trace-warnings ... to show where the warning was created)
(node:5864) Warning: Accessing non-existent property ‘findOne’ of module exports inside circular dependency
(node:5864) Warning: Accessing non-existent property ‘remove’ of module exports inside circular dependency
(node:5864) Warning: Accessing non-existent property ‘updateOne’ of module exports inside circular dependency
(node:5864) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to MongoClient.connect.
console.error
Something went wrong in getMovieByID: MongoError: user is not allowed to do action [find] on [sample_mflix.movies]

  312 |       // TODO Ticket: Error Handling
  313 |       // Catch the InvalidId error by string matching, and then handle it.
> 314 |       console.error(`Something went wrong in getMovieByID: ${e}`)
      |               ^
  315 |       throw e
  316 |     }
  317 |   }

  at error (src/dao/moviesDAO.js:314:15)
  at tryCatch (node_modules/regenerator-runtime/runtime.js:45:40)
  at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:271:22)
  at Generator.prototype.<computed> [as throw] (node_modules/regenerator-runtime/runtime.js:97:21)
  at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
  at _throw (node_modules/@babel/runtime/helpers/asyncToGenerator.js:29:9)
  at processTicksAndRejections (node:internal/process/task_queues:96:5)

console.error
Unable to convert cursor to array or problem counting documents, MongoError: user is not allowed to do action [find] on [sample_mflix.movies]

  268 |       return { moviesList, totalNumMovies }
  269 |     } catch (e) {
> 270 |       console.error(
      |               ^
  271 |         `Unable to convert cursor to array or problem counting documents, ${e}`,
  272 |       )
  273 |       return { moviesList: [], totalNumMovies: 0 }

  at Function.error (src/dao/moviesDAO.js:270:15)
  at tryCatch (node_modules/regenerator-runtime/runtime.js:45:40)
  at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:271:22)
  at Generator.prototype.<computed> [as throw] (node_modules/regenerator-runtime/runtime.js:97:21)
  at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
  at _throw (node_modules/@babel/runtime/helpers/asyncToGenerator.js:29:9)
  at processTicksAndRejections (node:internal/process/task_queues:96:5)

FAIL test/db-connection.test.js
Connection
× Can access MFlix data (41ms)
× Can retrieve a movie by id (74ms)
× Can retrieve first page of movies (60ms)

● Connection › Can access MFlix data

MongoError: user is not allowed to do action [listCollections] on [sample_mflix.]

  at Connection.<anonymous> (node_modules/mongodb/lib/core/connection/pool.js:466:61)
  at Connection.emit (node:events:390:28)
  at processMessage (node_modules/mongodb/lib/core/connection/connection.js:364:10)
  at TLSSocket.<anonymous> (node_modules/mongodb/lib/core/connection/connection.js:533:15)
  at TLSSocket.emit (node:events:390:28)
  at addChunk (node:internal/streams/readable:315:12)
  at readableAddChunk (node:internal/streams/readable:289:9)
  at TLSSocket.Readable.push (node:internal/streams/readable:228:10)
  at TLSWrap.onStreamRead (node:internal/stream_base_commons:199:23)

● Connection › Can retrieve a movie by id

MongoError: user is not allowed to do action [find] on [sample_mflix.movies]

  at Connection.<anonymous> (node_modules/mongodb/lib/core/connection/pool.js:466:61)
  at Connection.emit (node:events:390:28)
  at processMessage (node_modules/mongodb/lib/core/connection/connection.js:364:10)
  at TLSSocket.<anonymous> (node_modules/mongodb/lib/core/connection/connection.js:533:15)
  at TLSSocket.emit (node:events:390:28)
  at addChunk (node:internal/streams/readable:315:12)
  at readableAddChunk (node:internal/streams/readable:289:9)
  at TLSSocket.Readable.push (node:internal/streams/readable:228:10)
  at TLSWrap.onStreamRead (node:internal/stream_base_commons:199:23)

● Connection › Can retrieve first page of movies

expect(received).toEqual(expected) // deep equality

Expected: 20
Received: 0

  26 |       totalNumMovies: numMovies,
  27 |     } = await MoviesDAO.getMovies()
> 28 |     expect(firstPage.length).toEqual(20)
     |                              ^
  29 |     expect(numMovies).toEqual(23530)
  30 |   })
  31 | })

  at toEqual (test/db-connection.test.js:28:30)
  at tryCatch (node_modules/regenerator-runtime/runtime.js:45:40)
  at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:271:22)
  at Generator.prototype.<computed> [as next] (node_modules/regenerator-runtime/runtime.js:97:21)
  at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
  at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
  at processTicksAndRejections (node:internal/process/task_queues:96:5)

Test Suites: 1 failed, 1 total
Tests: 3 failed, 3 total
Snapshots: 0 total
Time: 2.363s
Ran all test suites matching /db-connection/i.
Teardown Mongo Connection

Are you able to connect to your DB by shell
Is your URI correct in your env file
Does the user has all needed privileges?

1 Like

Earlier the user had privilege of read and write to any database. But also after changing the privilege to atlasAdmin it is same.

I am using the connection string in .env
MONGODB_URI=mongodb+srv://mflix.*****.mongodb.net/myFirstDatabase --username m220student
and I am able to visit the http://locathost/status page.

Earlier I was using
MONGODB_URI=mongosh mongodb+srv://mflix.####.mongodb.net/myFirstDatabase --username m220student
and was unable to visit the http://localhost:5000

I am not familiar with this course.May be you have to create app user and use it in your uri
Check our forum threads
Also you cannot use mongosh before your connect string in your uri
May be you meant shell connect method

Yes. We were asked to copy the shell connection commands and use it as URI.
But the issue is why are these errors there for permission. From my view this can be the maximum privilege provided.

I think your uri format is not ok
Did you check other threads in our forum?
It should be like
Mongodb+srv://user:pwd@yourhostname
Double check exact syntax
Just gave it as tip/guidance

1 Like

Tried with that also. Same errors:

Connection
× Can access MFlix data (53ms)
× Can retrieve a movie by id (35ms)
× Can retrieve first page of movies (87ms)

● Connection › Can access MFlix data

expect(received).toContain(expected) // indexOf

Expected value: "movies"
Received array: []

  10 |     const collections = await mflix.listCollections().toArray()
  11 |     const collectionNames = collections.map(elem => elem.name)
> 12 |     expect(collectionNames).toContain("movies")
     |                             ^
  13 |     expect(collectionNames).toContain("comments")
  14 |     expect(collectionNames).toContain("users")
  15 |   })

  at toContain (test/db-connection.test.js:12:29)
  at tryCatch (node_modules/regenerator-runtime/runtime.js:45:40)
  at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:271:22)
  at Generator.prototype.<computed> [as next] (node_modules/regenerator-runtime/runtime.js:97:21)
  at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
  at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
  at processTicksAndRejections (node:internal/process/task_queues:96:5)

● Connection › Can retrieve a movie by id

TypeError: Cannot read properties of null (reading 'title')

  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:45:40)
  at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:271:22)
  at Generator.prototype.<computed> [as next] (node_modules/regenerator-runtime/runtime.js:97:21)
  at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
  at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
  at processTicksAndRejections (node:internal/process/task_queues:96:5)

● Connection › Can retrieve first page of movies

expect(received).toEqual(expected) // deep equality

Expected: 20
Received: 0

  26 |       totalNumMovies: numMovies,
  27 |     } = await MoviesDAO.getMovies()
> 28 |     expect(firstPage.length).toEqual(20)
     |                              ^
  29 |     expect(numMovies).toEqual(23530)
  30 |   })
  31 | })

  at toEqual (test/db-connection.test.js:28:30)
  at tryCatch (node_modules/regenerator-runtime/runtime.js:45:40)
  at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:271:22)
  at Generator.prototype.<computed> [as next] (node_modules/regenerator-runtime/runtime.js:97:21)
  at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
  at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
  at processTicksAndRejections (node:internal/process/task_queues:96:5)

Test Suites: 1 failed, 1 total
Tests: 3 failed, 3 total
Snapshots: 0 total
Time: 1.815s, estimated 2s
Ran all test suites matching /db-connection/i.
Teardown Mongo Connection

There is no mongo access error
Your test results are failing due to some other issue
You may have to check your code/logic

1 Like

This

or

Have you loaded the sample data set that is required?

Post your complete configuration file. Some others have misspelled the database name in the past.

1 Like

Is this dataset the sample dataset from cloud. Because I can’t find any dataset in handouts.

Go at Chapter 0: Introduction and Setup - Lab (Ungraded): Create or Reuse Atlas Cluster

and search the string Load Sample Dataset.

After that also I am facing this issue:

onitoring engine, pass option { useUnifiedTopology: true } to MongoClient.connect.
console.error
Something went wrong in getMovieByID: MongoError: user is not allowed to do action [find] on [sample_mflix.movies]

  312 |       // TODO Ticket: Error Handling
  313 |       // Catch the InvalidId error by string matching, and then handle it.
> 314 |       console.error(`Something went wrong in getMovieByID: ${e}`)
      |               ^
  315 |       throw e
  316 |     }
  317 |   }

  at error (src/dao/moviesDAO.js:314:15)
  at tryCatch (node_modules/regenerator-runtime/runtime.js:45:40)
  at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:271:22)
  at Generator.prototype.<computed> [as throw] (node_modules/regenerator-runtime/runtime.js:97:21)
  at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
  at _throw (node_modules/@babel/runtime/helpers/asyncToGenerator.js:29:9)
  at processTicksAndRejections (node:internal/process/task_queues:96:5)

FAIL test/db-connection.test.js
Connection
× Can access MFlix data (46ms)
× Can retrieve a movie by id (115ms)
× Can retrieve first page of movies (56ms)

● Connection › Can access MFlix data

MongoError: user is not allowed to do action [listCollections] on [sample_mflix.]

  at Connection.<anonymous> (node_modules/mongodb/lib/core/connection/pool.js:466:61)
  at Connection.emit (node:events:390:28)
  at processMessage (node_modules/mongodb/lib/core/connection/connection.js:364:10)
  at TLSSocket.<anonymous> (node_modules/mongodb/lib/core/connection/connection.js:533:15)
  at TLSSocket.emit (node:events:390:28)
  at addChunk (node:internal/streams/readable:315:12)
  at readableAddChunk (node:internal/streams/readable:289:9)
  at TLSSocket.Readable.push (node:internal/streams/readable:228:10)
  at TLSWrap.onStreamRead (node:internal/stream_base_commons:199:23)

● Connection › Can retrieve a movie by id

MongoError: user is not allowed to do action [find] on [sample_mflix.movies]

  at Connection.<anonymous> (node_modules/mongodb/lib/core/connection/pool.js:466:61)
  at Connection.emit (node:events:390:28)
  at processMessage (node_modules/mongodb/lib/core/connection/connection.js:364:10)
  at TLSSocket.<anonymous> (node_modules/mongodb/lib/core/connection/connection.js:533:15)
  at TLSSocket.emit (node:events:390:28)
  at addChunk (node:internal/streams/readable:315:12)
  at readableAddChunk (node:internal/streams/readable:289:9)
  at TLSSocket.Readable.push (node:internal/streams/readable:228:10)
  at TLSWrap.onStreamRead (node:internal/stream_base_commons:199:23)

● Connection › Can retrieve first page of movies

expect(received).toEqual(expected) // deep equality

Expected: 20
Received: 0

  26 |       totalNumMovies: numMovies,
  27 |     } = await MoviesDAO.getMovies()
> 28 |     expect(firstPage.length).toEqual(20)
     |                              ^
  29 |     expect(numMovies).toEqual(23530)
  30 |   })
  31 | })

  at toEqual (test/db-connection.test.js:28:30)
  at tryCatch (node_modules/regenerator-runtime/runtime.js:45:40)
  at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:271:22)
  at Generator.prototype.<computed> [as next] (node_modules/regenerator-runtime/runtime.js:97:21)
  at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
  at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
  at processTicksAndRejections (node:internal/process/task_queues:96:5)

Test Suites: 1 failed, 1 total
Tests: 3 failed, 3 total
Snapshots: 0 total
Time: 1.614s, estimated 2s
Ran all test suites matching /db-connection/i.
Teardown Mongo Connection
console.error
Unable to convert cursor to array or problem counting documents, MongoError: user is not allowed to do action [find] on [sample_mflix.movies]

  268 |       return { moviesList, totalNumMovies }
  269 |     } catch (e) {
> 270 |       console.error(
      |               ^
  271 |         `Unable to convert cursor to array or problem counting documents, ${e}`,
  272 |       )
  273 |       return { moviesList: [], totalNumMovies: 0 }

  at Function.error (src/dao/moviesDAO.js:270:15)
  at tryCatch (node_modules/regenerator-runtime/runtime.js:45:40)
  at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:271:22)
  at Generator.prototype.<computed> [as throw] (node_modules/regenerator-runtime/runtime.js:97:21)
  at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
  at _throw (node_modules/@babel/runtime/helpers/asyncToGenerator.js:29:9)
  at processTicksAndRejections (node:internal/process/task_queues:96:5)

D:\mflix-js>npm test -t db-connection

server@1.0.0 test
jest --passWithNoTests “db-connection”

Determining test suites to run…Setup Mongo Connection
(node:13324) Warning: Accessing non-existent property ‘count’ of module exports inside circular dependency
(Use node --trace-warnings ... to show where the warning was created)
(node:13324) Warning: Accessing non-existent property ‘findOne’ of module exports inside circular dependency
(node:13324) Warning: Accessing non-existent property ‘remove’ of module exports inside circular dependency
(node:13324) Warning: Accessing non-existent property ‘updateOne’ of module exports inside circular dependency
(node:13324) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to MongoClient.connect.
console.error
Something went wrong in getMovieByID: MongoError: user is not allowed to do action [find] on [sample_mflix.movies]

  312 |       // TODO Ticket: Error Handling
  313 |       // Catch the InvalidId error by string matching, and then handle it.
> 314 |       console.error(`Something went wrong in getMovieByID: ${e}`)
      |               ^
  315 |       throw e
  316 |     }
  317 |   }

  at error (src/dao/moviesDAO.js:314:15)
  at tryCatch (node_modules/regenerator-runtime/runtime.js:45:40)
  at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:271:22)
  at Generator.prototype.<computed> [as throw] (node_modules/regenerator-runtime/runtime.js:97:21)
  at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
  at _throw (node_modules/@babel/runtime/helpers/asyncToGenerator.js:29:9)
  at processTicksAndRejections (node:internal/process/task_queues:96:5)

console.error
Unable to convert cursor to array or problem counting documents, MongoError: user is not allowed to do action [find] on [sample_mflix.movies]

  268 |       return { moviesList, totalNumMovies }
  269 |     } catch (e) {
> 270 |       console.error(
      |               ^
  271 |         `Unable to convert cursor to array or problem counting documents, ${e}`,
  272 |       )
  273 |       return { moviesList: [], totalNumMovies: 0 }

  at Function.error (src/dao/moviesDAO.js:270:15)
  at tryCatch (node_modules/regenerator-runtime/runtime.js:45:40)
  at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:271:22)
  at Generator.prototype.<computed> [as throw] (node_modules/regenerator-runtime/runtime.js:97:21)
  at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
  at _throw (node_modules/@babel/runtime/helpers/asyncToGenerator.js:29:9)
  at processTicksAndRejections (node:internal/process/task_queues:96:5)

FAIL test/db-connection.test.js
Connection
× Can access MFlix data (42ms)
× Can retrieve a movie by id (73ms)
× Can retrieve first page of movies (46ms)

● Connection › Can access MFlix data

MongoError: user is not allowed to do action [listCollections] on [sample_mflix.]

  at Connection.<anonymous> (node_modules/mongodb/lib/core/connection/pool.js:466:61)
  at Connection.emit (node:events:390:28)
  at processMessage (node_modules/mongodb/lib/core/connection/connection.js:364:10)
  at TLSSocket.<anonymous> (node_modules/mongodb/lib/core/connection/connection.js:533:15)
  at TLSSocket.emit (node:events:390:28)
  at addChunk (node:internal/streams/readable:315:12)
  at readableAddChunk (node:internal/streams/readable:289:9)
  at TLSSocket.Readable.push (node:internal/streams/readable:228:10)
  at TLSWrap.onStreamRead (node:internal/stream_base_commons:199:23)

● Connection › Can retrieve a movie by id

MongoError: user is not allowed to do action [find] on [sample_mflix.movies]

  at Connection.<anonymous> (node_modules/mongodb/lib/core/connection/pool.js:466:61)
  at Connection.emit (node:events:390:28)
  at processMessage (node_modules/mongodb/lib/core/connection/connection.js:364:10)
  at TLSSocket.<anonymous> (node_modules/mongodb/lib/core/connection/connection.js:533:15)
  at TLSSocket.emit (node:events:390:28)
  at addChunk (node:internal/streams/readable:315:12)
  at readableAddChunk (node:internal/streams/readable:289:9)
  at TLSSocket.Readable.push (node:internal/streams/readable:228:10)
  at TLSWrap.onStreamRead (node:internal/stream_base_commons:199:23)

● Connection › Can retrieve first page of movies

expect(received).toEqual(expected) // deep equality

Expected: 20
Received: 0

  26 |       totalNumMovies: numMovies,
  27 |     } = await MoviesDAO.getMovies()
> 28 |     expect(firstPage.length).toEqual(20)
     |                              ^
  29 |     expect(numMovies).toEqual(23530)
  30 |   })
  31 | })

  at toEqual (test/db-connection.test.js:28:30)
  at tryCatch (node_modules/regenerator-runtime/runtime.js:45:40)
  at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:271:22)
  at Generator.prototype.<computed> [as next] (node_modules/regenerator-runtime/runtime.js:97:21)
  at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
  at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
  at processTicksAndRejections (node:internal/process/task_queues:96:5)

Test Suites: 1 failed, 1 total
Tests: 3 failed, 3 total
Snapshots: 0 total
Time: 1.342s, estimated 2s
Ran all test suites matching /db-connection/i.
Teardown Mongo Connection

Post a screenshot of user m220student privileges.

1 Like

Do I need to implement methods in moviesDAO.js for this?

As mentioned earlier:

The following error (because of the trailing dot after sample_mflix) seems to indicated that you have misspelled the database name.

This is the .env file. That is the one I have edited only
SECRET_KEY=My_SECRET
MFLIX_DB_URI=mongodb+srv://mflix.#####.mongodb.net/sample_mflix --username m220student
MFLIX_NS=sample_mflix
PORT=5000

Already mentioned a long time ago that

but you have

So just to be very clear.

  1. –username m220student should not be there
  2. m220student should be just after //
  3. just after m220student you should have a :
  4. right after the : you should have the password
  5. then between the password and your cluster name you need a @

This will look a lot like what was in the configuration file that was distribute with the course which look like:

# Ticket: Connection
# Rename this file to .env after filling in your MFLIX_DB_URI and your SECRET_KEY
# Do not surround the URI with quotes
SECRET_KEY=super_secret_key_you_should_change
MFLIX_DB_URI=mongodb+srv://m220student:m220password@<your-atlas-cluster-address>
MFLIX_NS=sample_mflix
PORT=5000

So I really do not understand how it can gone from:

MFLIX_DB_URI=mongodb+srv://m220student:m220password@<your-atlas-cluster-address>

to

and to

The only thing that had to be done is to replace
<your-atlas-cluster-address>
with your atlas cluster address which is mflix.####.mongodb.net.

Do I need to do TODO in test/config/mongoEnvironment.js?

// TODO: Connection Pooling
// Set the connection pool size to 50 for the testing environment.
// TODO: Timeouts
// Set the write timeout limit to 2500 milliseconds for the testing environment.

Thanks for the solution.

But in the Ticket is mentioned:
2. Copy the connection string. Select that you’d like to connect with the Mongo shell, version 3.6 or later . This will give you the srv connection string.

But the connection string you provided was mentioned in Connecting to Compass. Was it same?