MongoDB and Mongoose - Install and Set Up Mongoose

I have created the database and inserted the urls into the secrets folder.
and get the following error (person is not defined) in the console. Also i cant find a way to open the window that shows the link to post when completing the challenges.

npm run start

fcc-mongo-mongoose-challenges@0.0.1 start
node server.js

/home/runner/boilerplate-mongomongoose-2/myApp.js:59
exports.PersonModel = Person;
^

ReferenceError: Person is not defined
at Object. (/home/runner/boilerplate-mongomongoose-2/myApp.js:59:23)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions…js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object. (/home/runner/boilerplate-mongomongoose-2/server.js:67:16)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions…js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47

Node.js v18.12.1
exit status 1


require('dotenv').config();
let mongoose = require('mongoose')
mongoose.connect('mongodb+srv://cmarcinkiewicz2000:<password>@cluster0.pmn1ydn.mongodb.net/?retryWrites=true&w=majority', { useNewUrlParser: true, useUnifiedTopology: true });

const createAndSavePerson = (done) => {
  done(null /*, data*/);
};

dont know if this link will work
boilerplate-mongomongoose (2) - Replit

Your browser information:

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

Challenge: MongoDB and Mongoose - Install and Set Up Mongoose

Link to the challenge:

Your mongoose.connect command should not directly reference your database URI.
It shouldn’t be anywhere in your public code.
However, unless you’ve redacted your password when you pasted your code here, it’s also not a valid URI anyway, is it should contain your password.
You should store it in an environment variable in your Secrets tab and then reference the variable in your mongoose.connect command (e.g. as process.env.MONGO_URI).

Also.

You deleted the let Person; declaration from the code. The export at the bottom needs that identifier to have been declared and be in an available scope.

Put it back and leave it undefined but declared, until you are ready to assign it a value (the model).

I actually started and restarted the course and it passed with the same code but i still get errors in the console i dont know if these errors are normal

npm run start

fcc-mongo-mongoose-challenges@0.0.1 start
node server.js

Your app is listening on port 3000
/home/runner/boilerplate-mongomongoose-1/node_modules/mongodb/lib/cmap/connection.js:299
callback(new MongoError(document));
^

MongoError: bad auth : authentication failed
at MessageStream.messageHandler (/home/runner/boilerplate-mongomongoose-1/node_modules/mongodb/lib/cmap/connection.js:299:20)
at MessageStream.emit (node:events:513:28)
at processIncomingData (/home/runner/boilerplate-mongomongoose-1/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
at MessageStream._write (/home/runner/boilerplate-mongomongoose-1/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
at writeOrBuffer (node:internal/streams/writable:392:12)
at _write (node:internal/streams/writable:333:10)
at Writable.write (node:internal/streams/writable:337:10)
at TLSSocket.ondata (node:internal/streams/readable:766:22)
at TLSSocket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23) {
ok: 0,
 npm run start

fcc-mongo-mongoose-challenges@0.0.1 start
node server.js

Your app is listening on port 3000
GET
GET
/home/runner/boilerplate-mongomongoose-1/node_modules/mongodb/lib/cmap/connection.js:299
callback(new MongoError(document));
^

MongoError: bad auth : authentication failed
at MessageStream.messageHandler (/home/runner/boilerplate-mongomongoose-1/node_modules/mongodb/lib/cmap/connection.js:299:20)
at MessageStream.emit (node:events:513:28)
at processIncomingData (/home/runner/boilerplate-mongomongoose-1/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
at MessageStream._write (/home/runner/boilerplate-mongomongoose-1/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
at writeOrBuffer (node:internal/streams/writable:392:12)
at _write (node:internal/streams/writable:333:10)
at Writable.write (node:internal/streams/writable:337:10)
at TLSSocket.ondata (node:internal/streams/readable:766:22)
at TLSSocket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23) {
ok: 0,
code: 8000,
codeName: ‘AtlasError’
}

Node.js v18.12.1
exit status 1

boilerplate-mongomongoose (1) - Replit

I guess i am supposed to type the password into the url and just use the secret variable?

Yes, as @lasjorg pointed out, your repl was crashing before because Person was uninitiated but you’re still not correctly connecting to your database, so now you’re getting an authentication error.
You should replace the URI in your mongoose.connect command with a reference to the env variable.
The actual URI should be stored only in the env variable (in your Secrets tab), and should explicitly include your password.

I need to read things a little more closely didnt see that I had to add my password in when i got the url from the database. I don’t know why it passed the tests? But it is working ok now. This is all new to me