Console.error Something went wrong in getMovieByID: MongoError: user is not allowed to do action [find] on [sample_mflix.movies]

Hi,
I´m doing the M220JS course and Im troying to make the first ticket from the course.
I can connect properly to the database, but when I try to do the test these errors apears:

C:\Users\pablo\Downloads\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:13304) Warning: Accessing non-existent property ‘count’ of module exports inside circular dependency
(Use node --trace-warnings ... to show where the warning was created)
(node:13304) Warning: Accessing non-existent property ‘findOne’ of module exports inside circular dependency
(node:13304) Warning: Accessing non-existent property ‘remove’ of module exports inside circular dependency
(node:13304) Warning: Accessing non-existent property ‘updateOne’ of module exports inside circular dependency
(node:13304) 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 _callee6$ (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)

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._callee5$ (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)

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

● 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 processMessage (node_modules/mongodb/lib/core/connection/connection.js:364:10)
  at TLSSocket.<anonymous> (node_modules/mongodb/lib/core/connection/connection.js:533:15)

● 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 processMessage (node_modules/mongodb/lib/core/connection/connection.js:364:10)
  at TLSSocket.<anonymous> (node_modules/mongodb/lib/core/connection/connection.js:533:15)

● 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 _callee4$ (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)

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


I don´t know this is happening, because I follow all the instructions.

Thank´s for everyone.

Most likely you did not created the database user with the privileges indicated in the instructions.

I have follow all the instructions in the course, even creating the user thta they say me. So I don´know why I have having this error.

Post a screenshot of the user with its privilege you have created.

Go in your Atlas cluster, press Database Access on the left under SECURITY.

Also post the URI you are using.

Here is the Uri: mongodb+srv://mflix.1gz8b.mongodb.net/myFirstDatabase
If I have to include the original connection string : mongosh “mongodb+srv://mflix.1gz8b.mongodb.net/myFirstDatabase” --apiVersion 1 --username m220student

Aren’t you supposed to specify the username and password as part of the URI?

Something like:

mongodb+srv://m220student:RealPassword@mflix.1gz8b.mongodb.net/myFirstDatabase

Post the content of the configuration file.

The .env archive I supose.

You are missing

like

Thank you. Now works properly.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.