Stuck in "Install and Set Up Mongoose" on 19th May 2022

Tell us what’s happening:
Hi, I’m confusing about the challenge “Install and Set Up Mongoose”.
I’ve read past topics but I still wasn’t able to find a solution.

I’ve passed two checks :
“mongodb” dependency should be in package.json
“mongoose” dependency should be in package.json

but can’t pass:
“mongoose” should be connected to a database

Here is my code.

myApp.js

const mongoose = require("mongoose");
mongoose.connect(process.env['MONGO_URI'], { useNewUrlParser: true, useUnifiedTopology: true });

package.json

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

Secrets
topic-secrets

Console

 npm start

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

the options [useUnifiedTopology] is not supported
Your app is listening on port 3000
(node:4718) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'split' of null
    at parseSrvConnectionString (/home/runner/boilerplate-mongomongoose-1/node_modules/mongodb-core/lib/uri_parser.js:40:23)
    at parseConnectionString (/home/runner/boilerplate-mongomongoose-1/node_modules/mongodb-core/lib/uri_parser.js:421:12)
    at connect (/home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/node_modules/mongodb/lib/operations/mongo_client_ops.js:188:3)
    at connectOp (/home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/node_modules/mongodb/lib/operations/mongo_client_ops.js:292:3)
    at executeOperation (/home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/node_modules/mongodb/lib/utils.js:420:24)
    at MongoClient.connect (/home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/node_modules/mongodb/lib/mongo_client.js:168:10)
    at /home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/lib/connection.js:52
 npm start

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

the options [useUnifiedTopology] is not supported
Your app is listening on port 3000
(node:4860) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'split' of null
    at parseSrvConnectionString (/home/runner/boilerplate-mongomongoose-1/node_modules/mongodb-core/lib/uri_parser.js:40:23)
    at parseConnectionString (/home/runner/boilerplate-mongomongoose-1/node_modules/mongodb-core/lib/uri_parser.js:421:12)
    at connect (/home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/node_modules/mongodb/lib/operations/mongo_client_ops.js:188:3)
    at connectOp (/home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/node_modules/mongodb/lib/operations/mongo_client_ops.js:292:3)
    at executeOperation (/home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/node_modules/mongodb/lib/utils.js:420:24)
    at MongoClient.connect (/home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/node_modules/mongodb/lib/mongo_client.js:168:10)
    at /home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/lib/connection.js:527:12
    at new Promise (<anonymous>)
    at NativeConnection.Connection.openUri (/home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/lib/connection.js:524:19)
    at Mongoose.connect (/home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/lib/index.js:271:15)
    at Object.<anonymous> (/home/runner/boilerplate-mongomongoose-1/myApp.js:3:10)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
(node:4860) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:4860) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Since there is a message “the options [useUnifiedTopology] is not supported” in my console, I tried to remove this from my connect method but it still doesn’t work.


Would you see why my solution doesn’t work? If you have any idea, please help me.
Thank you.



Also, here is my status on MongoDB.




Your project link(s)

solution: boilerplate-mongomongoose-1 - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36 Edg/101.0.1210.47

Challenge: Install and Set Up Mongoose

Link to the challenge:

This might have nothing to do, but worth a shot: try removing the double quotes in your ENV.SECRET and see if it works.

The errors smells to me like it’s failing to parse to url.
More a guess, than a certainty but worth a shot imho. :smile:

1 Like

Hello,

Thank you for your replying! It worked!


However, I needed one more little step to pass the challenge.
So let me share for future readers.

First, you need to remove the double quotes from your Secrets.
topic-secrets2


Then, you also need to remove this portion { useNewUrlParser: true, useUnifiedTopology: true } from your connect method. Like this:

const mongoose = require("mongoose");
mongoose.connect(process.env['MONGO_URI']);

This step doesn’t along with the challenge direction, but it is necessary at least on 20th May 2022 and on my environment.


Anyway, I really appreciate your advice. I feel better now. Thank you!