I have been struggling for a while now to pass the first class of MongoDB and Mongoose (https://www.freecodecamp.org/learn/back-end-development-and-apis/mongodb-and-mongoose/install-and-set-up-mongoose)
I copied the boilerplate from GitHub - freeCodeCamp/boilerplate-mongomongoose: A boilerplate for the freeCodeCamp curriculum.
I changed the sample.env to .env file. in my .env file I have:
MONGO_URI='mongodb+srv://karelwillemyns:aPassword@cluster0.g6b3uyq.mongodb.net/fcc-mongodb-and-mongoose?retryWrites=true&w=majority'type or paste code here
I tried with and without quotes (on FCC is instructed with, chatGPT insisted it should be without)
The current start of myApp.js is:
require('dotenv').config();
console.log('MONGO_URI:', process.env.MONGO_URI);
/** # MONGOOSE SETUP #
/* ================== */
/** 1) Install & Set up mongoose */
const mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true });
let Person;
package.json has mongoose 5.11.15 in dependencies:
{
"name": "fcc-mongo-mongoose-challenges",
"version": "0.0.1",
"description": "A boilerplate project",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"body-parser": "^1.15.2",
"dotenv": "^8.2.0",
"express": "^4.12.4",
"mongoose": "^5.11.15"
},
"repository": {
"type": "git",
"url": "https://github.com/freeCodeCamp/boilerplate-mongomongoose.git"
},
"keywords": [
"node",
"mongoose",
"express"
],
"license": "MIT"
}
yet these are the test results when passing the solution link:
// running tests 1. “mongoose version ^5.11.15” dependency should be in package.json 2. “mongoose” should be connected to a database // tests completed // console output [Error] [Error]
Tests
-
Failed:1. “mongoose version ^5.11.15” dependency should be in package.json
-
Failed:2. “mongoose” should be connected to a database
In the terminal I get the following message when npm run start is used:
Debugger attached.
fcc-mongo-mongoose-challenges@0.0.1 start
node server.js
Debugger attached.
MONGO_URI: mongodb+srv://karelwillemyns:W4chtw00rd@cluster0.g6b3uyq.mongodb.net/fcc-mongodb-and-mongoose?retryWrites=true&w=majority
Your app is listening on port 3000
(node:20116) [DEP0170] DeprecationWarning: The URL mongodb://karelwillemyns:W4chtw00rd@ac-xlrhkpe-shard-00-02.g6b3uyq.mongodb.net:27017,ac-xlrhkpe-shard-00-00.g6b3uyq.mongodb.net:27017,ac-xlrhkpe-shard-00-01.g6b3uyq.mongodb.net:27017/fcc-mongodb-and-mongoose?authSource=admin&replicaSet=atlas-bfp6b4-shard-0&retryWrites=true&w=majority&ssl=true is invalid. Future versions of Node.js will throw an error.
(Use node --trace-deprecation ...
to show where the warning was created)
Waiting for the debugger to disconnect…
C:\Users\Karel\Documents\Programeren\VisualBasic\FCC6_Back End Development and APIs\MongoDB and Mongoose\node_modules\mongodb\lib\cmap\connection.js:299 callback(new MongoError(document));
^
MongoError: bad auth : authentication failed
at MessageStream.messageHandler (C:\Users\Karel\Documents\Programeren\VisualBasic\FCC6_Back End Development and APIs\MongoDB and Mongoose\node_modules\mongodb\lib\cmap\connection.js:299:20)
at MessageStream.emit (node:events:518:28)
at processIncomingData (C:\Users\Karel\Documents\Programeren\VisualBasic\FCC6_Back End Development and APIs\MongoDB and Mongoose\node_modules\mongodb\lib\cmap\message_stream.js:144:12)
at MessageStream._write (C:\Users\Karel\Documents\Programeren\VisualBasic\FCC6_Back End Development and APIs\MongoDB and Mongoose\node_modules\mongodb\lib\cmap\message_stream.js:42:5)
at writeOrBuffer (node:internal/streams/writable:572:12)
at _write (node:internal/streams/writable:501:10)
at Writable.write (node:internal/streams/writable:510:10)
at TLSSocket.ondata (node:internal/streams/readable:1009:22)
at TLSSocket.emit (node:events:518:28)
at addChunk (node:internal/streams/readable:561:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
at Readable.push (node:internal/streams/readable:392:5)
at TLSWrap.onStreamRead (node:internal/stream_base_commons:189:23) {
ok: 0,
code: 8000,
codeName: ‘AtlasError’
}
Node.js v22.14.0
Waiting for the debugger to disconnect…
I do not understand why a bad auth error is given. password and username have been reviewed many times.
Also, I suppose that the first test (1. “mongoose version ^5.11.15” dependency should be in package.json) should be passed even with a bad connection…