MongoError: database name must be a string

I’m using replit and I can’t connect to my database for the first challenge, Here’s what my code looks like:

const mongoose = require('mongoose');

const myURI = process.env['MONGO_URI'];

mongoose.connect(myURI, { useNewUrlParser: true, useUnifiedTopology: true });

This is the output I get from the console:

> fcc-mongo-mongoose-challenges@0.0.1 start /home/runner/boilerplate-mongomongoose
> node server.js

the options [useUnifiedTopology] is not supported
Your app is listening on port 3000
      throw err;

MongoError: database name must be a string
    at Function.create (/home/runner/boilerplate-mongomongoose/node_modules/mongodb-core/lib/error.js:43:12)
    at validateDatabaseName (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/node_modules/mongodb/lib/operations/db_ops.js:700:22)
    at new Db (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/node_modules/mongodb/lib/db.js:181:3)
    at MongoClient.db (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/node_modules/mongodb/lib/mongo_client.js:268:14)
    at /home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/connection.js:527:62
    at /home/runner/boilerplate-mongomongoose/node_modules/mongoose/node_modules/mongodb/lib/utils.js:414:17
    at executeCallback (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/node_modules/mongodb/lib/utils.js:406:9)
    at /home/runner/boilerplate-mongomongoose/node_modules/mongoose/node_modules/mongodb/lib/operations/mongo_client_ops.js:286:5
    at connectCallback (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/node_modules/mongodb/lib/operations/mongo_client_ops.js:241:5)
    at /home/runner/boilerplate-mongomongoose/node_modules/mongoose/node_modules/mongodb/lib/operations/mongo_client_ops.js:463:7
    at processTicksAndRejections (internal/process/task_queues.js:79:11) {
  driver: true,
  [Symbol(mongoErrorContextSymbol)]: {}
npm ERR! errno 1
npm ERR! fcc-mongo-mongoose-challenges@0.0.1 start: `node server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the fcc-mongo-mongoose-challenges@0.0.1 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2022-05-19T16_28_47_976Z-debug.log
exit status 1

What version of mongoose did you install?

Honestly I’m not sure.

    "dependencies": {
        "body-parser": "^1.15.2",
        "dotenv": "^8.2.0",
        "express": "^4.12.4",
        "mongodb": "^3.6.0",
        "mongoose": "^5.4.0"


But I guess it’s probably the one in the dependencies. since I installed it like this:

npm install mongoose@5.4.0

You can check it.

cd node_modules/mongoose
node -p "require('./package.json').version"

What does your connection string look like? Post it without the password.

Yeah the version is 5.4.0.

Here’s the URI:


How did you get that? I think it needs the DB name in the string.


That’s the string that I got from mongodb when I chose “connect your application”, I’m not sure what I’m supposed to do.

It seem Atlas changed something. You used to get the the DB name with the connection string you don’t anymore. And I think the connection string without the DB name breaks with the version of mongoose.

On the Atlas dashboard under “Deployment” click “Database” now click the “Browse Collections” button it should show you the DB name.

Add it to the connection string after the / and before the ?retry

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