Mongo DB won't save document

Tell us what’s happening:

When I use my form to create a document, I see nothing coming up in mongoDB. Can anyone help?

Your code so far
My repl is here!

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36.

Challenge: Issue Tracker

Link to the challenge:

Hey @sbrevolution5, did you set your env variable correctly?
When running your repl I get this error:

MongooseError: The uri parameter to openUri() must be a string, got “undefined”. Make sure the first parameter to mongoose.connect() or mongoose.createConnection() is a string.

Meaning that

const uri = process.env.DB

is undefined.

May just be a case of repl.it, but may a starting point.

I think that is because of repl.it. I’m not seeing that error at all. I’ve updated the file and pasted the uri directly in so that there’s no confusion, It may simply be because the .env file is hidden for other users.

For the record. I get a connection successful log every time I run it. but I’m not seeing the save success log that I added when the document saves

Yeah, seems repl keeps the env variables hidden, and for good reasons :slight_smile:
My suggestion is to keep it that way, and don’t show your connection string around, that’s a potential security issue.

With that out of the way we know it’s connecting.
Do you have the error log when saving a new issue?

Actually I made a mistake, wasn’t logging the error to the console. Looks like its that theres no ID field. This turned out to be because I had put _id in my schema, but not inserted a value. The easiest fix was to take it out of schema

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