maxPoolSize error in test


when doing pytest -m connection_pooling


def get_db():
Configuration method to return db instance
db = getattr(g, “_database”, None)
MFLIX_DB_URI = current_app.config[“MFLIX_DB_URI”]
if db is None:

    Ticket: Connection Pooling

    Please change the configuration of the MongoClient object by setting the
    maximum connection pool size to 50 active connections.

    Ticket: Timeouts

    Please prevent the program from waiting indefinitely by setting the
    write concern timeout limit to 2500 milliseconds.

    db = g._database = MongoClient(
    # TODO: Connection Pooling
    # Set the maximum connection pool size to 50 active connections.
    # TODO: Timeouts
    # Set the write timeout limit to 2500 milliseconds.
return db

You URI is not correct.

Oh I see now

but I have problems with Atlas so I changed to MongoDB on localhost - will that work as it is not clustered?

In .ini it is defined as:

MFLIX_DB_URI = mongodb://localhost:27017/mflix and I use this in code:

db = getattr(g, "_database", None)
MFLIX_DB_URI = current_app.config["mongodb://localhost:27017/mflix"]
if db is None:


If you change the URI you do not have to change the code. Please do not change code outside the daos.


Hello Erik_09475,

Thanks for the note. To use a local mongod instance, you should only have to edit the .ini file.


1 Like


now I have this as URI:

MFLIX_DB_URI = current_app.config["MFLIX_DB_URI"]

Then I am back at #1 again - I get this error:



It looks like you don’t have any users created on your local mongod instance, which is causing the API to error out. Try connecting to your instance and creating the m220student user with the following command:

  user: "m220student",
  pwd: "m220password",
  roles: [
    { role: "readWriteAnyDatabase", db: "admin" }

This should allow the lab to validate. In the future, we will change the error handling in the get_configuration() method to avoid this scenario.

I hope this helps!


1 Like

When you say I have this as URI, do you mean that you have the following line in your .ini file?

MFLIX_DB_URI = current_app.config[“MFLIX_DB_URI”]

If this is the case then it is wrong. This looks like the code from At the right of the equal you put the URI. So rather than having current_app.config[“MFLIX_DB_URI”] you will have your URI such as mongodb://localhost:27017/mflix. And you leave the corresponding code untouch in

Just to be clear. In your .ini file you have:

MFLIX_DB_URI = mongodb://…

In you have:

MFLIX_DB_URI = current_app.config[“MFLIX_DB_URI”]

You see the code in does the correspondence between the python variable MFLIX_DB_URI and the configuration value in the .ini file that has the same name. The instructions asked you to change the URI in the config file not in the code. You should only change the code in the TODO sections.

1 Like

thanks for help - succeeded with these 3 steps:

In command prompt:

use mflix
db.createUser( { user: “m220student”,
pwd: “m220password”,
roles: [ { role: “clusterAdmin”, db: “admin” },
{ role: “readAnyDatabase”, db: “admin” },
“readWrite”] } )

the .ini file:

SECRET_KEY = my_secret_key
MFLIX_DB_URI = mongodb://m220student:m220password@localhost:27017/mflix

SECRET_KEY = super_secret_testing_key
MFLIX_DB_URI = mongodb://m220student:m220password@localhost:27017/mflix

in mongod.cnf:

security.authorization: enabled

1 Like

Thanks a lot! This worked for me