Not able to read from mflix.movies

Application is up and running properly but not able to retrieve the records from “mflix.movies”.

2019-01-10 10:38:06.176 INFO 20016 — [nio-5000-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet ‘dispatcherServlet’
2019-01-10 10:38:06.176 INFO 20016 — [nio-5000-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet ‘dispatcherServlet’: initialization started
2019-01-10 10:38:06.248 INFO 20016 — [nio-5000-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet ‘dispatcherServlet’: initialization completed in 72 ms
2019-01-10 10:38:06.769 INFO 20016 — [nio-5000-exec-1] org.mongodb.driver.connection : Opened connection [connectionId{localValue:4, serverValue:6303}] to mflix-shard-00-00-tp7vq.mongodb.net:27017
2019-01-10 10:38:06.916 ERROR 20016 — [nio-5000-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path threw exception [Request processing failed; nested exception is com.mongodb.MongoQueryException: Query failed with error code 8000 and error message ‘user is not allowed to do action [find] on [mflix.movies]’ on server mflix-shard-00-00-tp7vq.mongodb.net:27017] with root cause

com.mongodb.MongoQueryException: Query failed with error code 8000 and error message ‘user is not allowed to do action [find] on [mflix.movies]’ on server mflix-shard-00-00-tp7vq.mongodb.net:27017
at com.mongodb.operation.FindOperation$1.call(FindOperation.java:707) ~[mongodb-driver-core-3.9.1.jar:na]
at com.mongodb.operation.FindOperation$1.call(FindOperation.java:696) ~[mongodb-driver-core-3.9.1.jar:na]
at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:462) ~[mongodb-driver-core-3.9.1.jar:na]
at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:406) ~[mongodb-driver-core-3.9.1.jar:na]
at com.mongodb.operation.FindOperation.execute(FindOperation.java:696) ~[mongodb-driver-core-3.9.1.jar:na]
at com.mongodb.operation.FindOperation.execute(FindOperation.java:83) ~[mongodb-driver-core-3.9.1.jar:na]
at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:179) ~[mongodb-driver-sync-3.9.1.jar:na]
at com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:132) ~[mongodb-driver-sync-3.9.1.jar:na]
at com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:86) ~[mongodb-driver-sync-3.9.1.jar:na]
at mflix.api.daos.MovieDao.getMovies(MovieDao.java:107) ~[classes/:na]

The same error happens with me too, also when I run the unit tests.

To fix the error, it’s necessary to configure your spring.mongodb.uri value like this:

“mongodb+srv://m220student:m220password@{ your host here}”

Hi @vensanravi,

@brunomathidios stands correct. Do not forget to set the "spring.mongodb.uri" in the application.properties file. Also, make sure that the Atlas cluster user created is correctly set with the ip whitelisting including your IP address.

We recommend, for this course purposes only, to allow connections from any address by setting the CIDR block “0.0.0.0/32” in the ip whitelist.

N.

1 Like

In the course they forgot to add the username and password for the property spring.mongodb.uri inside the application.properties

Your final spring.mongodb.uri like below.

spring.mongodb.uri=mongodb+srv://m220student:m220password@<YOUR_HOST_NAME>

1 Like

Thank you, adding user & password in uri helped! :smile:

Instructions definitely should be updated with this info

spring.mongodb.uri=mongodb://cluster0-shard-00-00-phzjk.mongodb.net:27017,cluster0-shard-00-01-phzjk.mongodb.net:27017,cluster0-shard-00-02-phzjk.mongodb.net:27017/test?replicaSet=Cluster0-shard-0 --ssl --authenticationDatabase admin --username m220student --password m220password

I am using this one since i have mongdb3.4.

Its still showing same error

Hi @Harsh3,

We always recommend to use the latest MongoDB version which is 4.0.10 (Enterprise). As there have been so many updates since 3.4 version and there might be some labs which you won’t be able to complete due to the same reason.

You can download it here.

Please let me know if you have any questions.

Kanika