Hi all, how are you?. I’m the first exercise of mongoDB of the certification about backend development, until now when I try to validate the challenge 2 of 3 tests passes but the third which is to test the connection with my mongo database dosen’t work.
My package.json has on dependencies the following
"dependencies": {
"body-parser": "^1.15.2",
"dotenv": "^8.2.0",
"express": "^4.12.4",
"mongodb": "~3.6.0",
"mongoose": "~5.4.0"
},
the code tath defines the the const for the database is the following and is in the file
myApp.js
const mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI);
the connect function calls the MONGO_URI from process.env and I have that file created with the variable defined and initializated, I also created the variable MONGO_URI in the secrets area. I saw too that the project only take the variable from secrets variables because although I’m taking the variable from process.env, the one that is being taken is the stored in secrets.
Right know the project is giving me all this messages on the console of repl
npm start
> fcc-mongo-mongoose-challenges@0.0.1 start /home/runner/boilerplate-mongomongoose
> node server.js
"mongodb+srv://vra:mata789@cluster0.limy9.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"
(node:413) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
Your app is listening on port 3000
(node:413) UnhandledPromiseRejectionWarning: Error: Invalid schema, expected `mongodb` or `mongodb+srv`
at module.exports (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/node_modules/mongodb/lib/url_parser.js:21:21)
at deprecated (internal/util.js:89:15)
at connect (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/node_modules/mongodb/lib/operations/mongo_client_ops.js:188:3)
at connectOp (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/node_modules/mongodb/lib/operations/mongo_client_ops.js:292:3)
at executeOperation (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/node_modules/mongodb/lib/utils.js:420:24)
at MongoClient.connect (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/node_modules/mongodb/lib/mongo_client.js:168:10)
at /home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/connection.js:527:12
at new Promise (<anonymous>)
at NativeConnection.Connection.openUri (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/connection.js:524:19)
at Mongoose.connect (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/index.js:271:15)
at Object.<anonymous> (/home/runner/boilerplate-mongomongoose/myApp.js:4: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:413) 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:413) [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.
GET
GET
GET
I know that secrets must never be printed or be public but since this is a challenge I don’t have any problem showing this MONGO_URI variable because is a general one.
The fact is that the project from repl apparently never connects with the database at mongo because freecode page always shows the following
// running tests
"mongoose" should be connected to a database
// tests completed
"mongodb" dependency should be in package.json
"mongoose" dependency should be in package.json
"mongoose" should be connected to a database
thw first two tests after the phrase test completed are good but the third is the failing one, so, how can I solve this problem?.
I’ve recently noted that when I require mongoose then the editor at replit puts 3 points before ‘mongoose’ like seen bellow
and the editor puts the following message when I hover the cursor over the 3 points
[typescript]
Could not find a declaration file for module 'mongoose'. '/home/runner/boilerplate-mongomongoose/node_modules/mongoose/index.js' implicitly has an 'any' type.
Try `npm install @types/mongoose` if it exists or add a new declaration (.d.ts) file containing `declare module 'mongoose';`
I don’t know if this is a problem of replit page or I’m doing a bad coding here, can somone help me here?
Thanks in advance for the help.